I have a code to upload an image, then creates thumbnail on the fly for this uploaded image.
The following code that creates the thumbnail (thumb.php).
$fileName = filter_input(INPUT_GET, 'src');
$width = filter_input(INPUT_GET, 'width', FILTER_SANITIZE_NUMBER_INT);
$height = filter_input(INPUT_GET, 'height', FILTER_SANITIZE_NUMBER_INT);
$im = imagecreatefromjpeg($fileName); //<=== the error message indicates to this line
$tmp_im = imagecreatetruecolor($width, $height);
$imWidth = imagesx($im);
$imHeight = imagesy($im);
imagecopyresampled($tmp_im, $im, 0, 0, 0, 0, $width, $height, $imWidth, $imHeight);
header("Content-type: image/jpeg");
imagejpeg($tmp_im);
imagedestroy($im);
imagedestroy($tmp_im);
The following code that upload the image, then implement the creation of thumbnail for the uploaded image, then display this thumbnail.
require_once ('thumb.php');
$image_dir = "images/";
if($_FILES['photo']['error'] == 0){
$fileUPloaded = $_FILES['photo']['name'];
move_uploaded_file($_FILES['photo']['tmp_name'], $image_dir.$fileUPloaded);
echo "<a href='".$image_dir.$fileUPloaded."'><img src='thumb.php?src=".$image_dir.$fileUPloaded."&width=350&height=250' alt='' /></a>";
}
Now, why appears an error Warning: imagecreatefromjpeg(): Filename cannot be empty
.
Note that the image is uploaded, and was created thumbnail for uploaded image, and was displayed thumbnail. so, why that error message appear ?