What is the common error message encountered when using the imagecreatefromjpeg() function in PHP?

When using the imagecreatefromjpeg() function in PHP, a common error message encountered is "Warning: imagecreatefromjpeg(): 'filename.jpg' is not a valid JPEG file." This error occurs when the specified file is not a valid JPEG image or if the file path is incorrect. To solve this issue, make sure that the file path is correct and the image is indeed a valid JPEG file.

$filename = 'image.jpg';

// Check if the file exists and is a valid JPEG file before using imagecreatefromjpeg()
if (file_exists($filename) && exif_imagetype($filename) == IMAGETYPE_JPEG) {
    $image = imagecreatefromjpeg($filename);
    // Further processing of the image
} else {
    echo "Error: Invalid JPEG file or file not found.";
}