if ( $_FILES["ufile"]["type"] [$i] == "image/jpeg" || $_FILES["ufile"]["type"] [$i] == "image/jpg" || $_FILES["ufile"]["type"] [$i] == "image/png" || $_FILES["ufile"]["type"] [$i] == "image/gif" )
{
if ($_FILES["ufile"]["type"] [$i] == "image/png" || $_FILES["ufile"]["type"] [$i] == "image/gif" || $_FILES["ufile"]["type"] [$i] == "image/jpeg" || $_FILES["ufile"]["type"] [$i] == "image/jpg" )
{
$file=$_FILES["ufile"]["tmp_name"];
list($width, $height) = getimagesize($file);
$new_width = 200;
$new_height = 500;
$dst_image = imagecreatetruecolor($new_width,$new_height);
$src_image = imagecreatefromjpeg($_FILES["ufile"]["tmp_name"]);
imagecopyresized ($dst_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg(imagecreatefromstring(file_get_contents($dst_image)), "convert.jpg");
$actual_image_name = $name[$i].'.'.'jpg';
move_uploaded_file("convert.jpg", $path.$actual_image_name);
}
}
You are totally mis-using GD. $dst_image
is a GD image handle. It is not a file. So... file_get_contents()
will return boolean FALSE, since you're trying to fetch from something that is not a filename. imagecreatefromstring()
will return boolean false, since a boolean false is not an image string, and imagejpeg()
will return boolean FALSE since you're not passing it a GD Handle.
In short, your code could do with some improvement. You simply assume nothing could ever go wrong, don't ever check for failure, and those failures propagate onwards through the code.
All you really needed was
image_jpeg($dst_image, 'convert.jpg');
And then your move_uploaded_file
will also fail, since "convert.jpg" isn't an uploaded file. It's a file you've created yourself on the server. It may have been based on an uploaded file, but in and of itself is not an uploaded file. Why not just
image_jpeg($dst_image, "$path/$actual_image_name");