So i have an iphone app that that uploads an image to my webserver and i looked around and people seem to be doing something like
$data = file_get_contents($_FILES['file']['tmp_name']);
$image = imagecreatefromstring($data);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
I looked at the php docs, but i still don’t understand what the header() does; does it convert the image into whatever format i want?
And for the imagepng(), where is the image outputted to? memory? is that why i need the imagedestroy()?
and where would i put in
move_uploaded_file()
Thanks in advance!
Header is purely for the server to let the browser know “Oh hey this is a png image please render it so”
imagepngencodes it into the png format and “prints” to the outputimagedestroyfrees the memory taken by the image resource.If you need to force extension you can use mod_rewrite
Here’s a sample couple lines from my
.htaccess:Hope this helps!