PHP Getimagesize Empty Output

PHP getimagesize empty output

Faking the HTTP referer field seems to work on this one:

<?php
function getimgsize($url, $referer = '')
{
$headers = array(
'Range: bytes=0-32768'
);

/* Hint: you could extract the referer from the url */
if (!empty($referer)) array_push($headers, 'Referer: '.$referer);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);

$image = imagecreatefromstring($data);

$return = array(imagesx($image), imagesy($image));

imagedestroy($image);

return $return;
}

list($width, $heigth) = getimgsize('http://cor-forum.de/forum/images/smilies/zombie.png', 'http://cor-forum.de/forum/');

echo $width.' x '.$heigth;
?>

Source of code

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty warning message?

You checked if the form was submitted, but didn't check if the file was sent. In some cases, a form could be submitted but the file will not sent (i.e. file size is bigger then file size limit in config).

Use this:

if(isset($_POST["submit"]) && isset($_FILES['file'])) {
$file_temp = $_FILES['file']['tmp_name'];
$info = getimagesize($file_temp);
} else {
print "File not sent to server succesfully!";
exit;
}

You see && isset($_FILES['file']) is new

Or you can extend it

if(isset($_POST["submit"]) && isset($_FILES['file'])) {
$file_temp = $_FILES['file']['tmp_name'];
$info = getimagesize($file_temp);
}
elseif(isset($_POST["submit"]) && !isset($_FILES['file'])) {
print "Form was submitted but file wasn't send";
exit;
}
else {
print "Form wasn't submitted!";
exit;
}

getimagesize() doesn't output any result when trying to get dimensions of a public folder images

Problem is with this function

$img = asset ( 'uploads/products_thumbnails').'/'.$product->thumbnail_file_name;

Try accessing your public folder without asset function.

$img = 'uploads/products_thumbnails/'.$product->thumbnail_file_name;

Photo Upload getimagesize() warning - filename cannot be empty

OK everyone. I figured out what the issue was. Hopefully this will help someone in the future. So I checked my phpinfo() and found that upload_max_filesize was only set to 2M. I added php.ini to the directory of the offending file and included:

upload_max_filesize = 250M
post_max_size = 250M
max_execution_time = 300

date.timezone = "America/Los_Angeles"

I had to add the date.timezone because my system didn't like the fact that I didn't have it defined. Anyway this has resolved the issue.

getimagesize() won't work on my site (PHP)

I wrote out a blank php file and used getimagesize() on the url you posted and it returned the expected array of results. How you looked at your php error log to see if there are any other underlying errors that are preventing output? Does print_r() or var_dump() give anything?

  Array
(
[0] => 800
[1] => 600
[2] => 13
[3] => width="800" height="600"
[mime] => application/x-shockwave-flash
)

getimagesize() returns no data?

Lets look at the knowns:

  • You can upload .jpg, .gif, .png no problem
  • You are having problem uploading a specific .jpg image

These knowns lead me to believe that the problem image is too big for the current allowed upload_max_filesize in your php.ini settings:

$ -> php -i | fgrep -i size

upload_max_filesize => 2M => 2M

Try increasing the size to 6M or 8M and your bigger image should work.

getimagesize & non-Latin characters

It works if you urlencode the filename:

<?php
$external_link = 'https://example.com/storage/'.urlencode('image图片20170214003852.jpg');
//$external_link = 'https://nikonrumors.com/wp-content/uploads/2014/03/Nikon-1-V3-sample-photo.jpg';
if (list($width, $height, $type, $attr) = @getimagesize($external_link)) {
echo "Width=".$width. ', '."Height=".$height;
} else {
echo "image does not exist";
}
?>


Related Topics



Leave a reply



Submit