What are the potential pitfalls of manually changing file permissions for images in PHP?

Manually changing file permissions for images in PHP can lead to security vulnerabilities if not done correctly. It is important to ensure that the permissions are set appropriately to prevent unauthorized access to sensitive files. To avoid potential pitfalls, it is recommended to use PHP's built-in functions like `chmod()` to set file permissions programmatically.

// Set file permissions to 0644 for images
$filename = 'image.jpg';
$filepath = '/path/to/images/' . $filename;

if (file_exists($filepath)) {
    chmod($filepath, 0644);
    echo 'File permissions for image.jpg have been updated.';
} else {
    echo 'Image not found.';
}