Whit the follow code:
$file = fopen('php://input', 'r');
$temp = tmpfile();
$imageSize = stream_copy_to_stream($file, $temp);
$imageDimensions = getimagesize($file); // Error here
$imageInfos = pathinfo($_GET['selected-image']);
I get this error
getimagesize() expects parameter 1 to be string, resource given
Because $file is a resource of fopen. How I can have a resource and a string if I can’t read php://input twice?
UPDATE
I have tried this:
$file = fopen('php://input', 'r');
$tempName = tempnam(sys_get_temp_dir(), '.upload');
$imageSize = fwrite(fopen($tempName, 'w+'), stream_get_contents($file));
$imageDimensions = getimagesize($tempName);
$imageInfos = pathinfo($_GET['selected-image']);
// Unlinks and other stuffs
The error:
Notice: getimagesize() [function.getimagesize]: Read error! in
Thanks!
Because
getimagesize()only accepts string filenames, not resources, you will need to usetempnam()to create a temporary file with a name that you can pass togetimagesize().This assumes that the user running PHP has write and read permissions to the directory
/var/tmp, but if it doesn’t you can change to a directory that the user does have r/w permissions to.