Hi to everyone,
I've made a (very) simple script that takes an uploaded image, resizes it and then returns it to the output.
But while the image is correctly showed in the browser if I try to save it (save image as..), I find it's
only 8kb. And then I find it's not the image, but my php file... why? I think there's something wrong with headers, but i've really tried everything..
I try to post the code:
<?php
$img = imagecreatefromjpeg('upload_img/'.$_FILES['image']['name']);
//Image width and height
$sx = imagesx($img);
$sy = imagesy($img);
//Image resize
$resized_img = imagecreatetruecolor(542,409);
imagecopyresized($resized_img, $img, 0, 0, 0, 0, 542,409, $sx, $sy);
//Setting headers
header('Content-type: image/jpeg');
header('Content-Length: '.filesize(imagejpeg($resized_img)));
header('Content-Disposition: inline; filename="downloaded.jpg"');
//Return the output
imagejpeg($resized_img, 'downloaded.jpg');
imagedestroy($resized_img);
//Deleting the old file
unlink('upload_img/'.$_FILES['image']['name']);
exit;
?>