Warning: filesize (): stat failed for img.jpg

I am trying to get the image file size and I keep getting Warning: filesize(): stat failed for img.jpg

This is what I did:

$path = $_FILES['profile']['name'];
$path = iconv('UTF-8', 'ISO-8859-1',$path);
if (!in_array(pathinfo($path,PATHINFO_EXTENSION),$allowed)) {
    return "file";
} elseif (filesize($path)>(1024*600))

I can get the file extension without problems, but filesize()just doesn't work. I read a little and found this one , but this did not solve the problem. Any help is much appreciated!

+4
source share
3 answers

['name']in the $ _FILES array, is the name of the file on the CLIENT machine. This is only information and has absolutely nothing to do with what is actually stored on your server. You need to see ['tmp_name']where PHP temporarily stores the file on the server after the download is complete:

$path = $_FILES['profile']['tmp_name'];
                          ^^^^^^^^^^^^
+6
source

$_FILES['profile']['name'] ..

$_FILES['profile']['tmp_name'] 

. http://php.net/manual/en/reserved.variables.files.php

$_FILE['profile']['size']
+3
echo "---- NULL ---------------\n";
$path = null;
echo "File size is: " . filesize($path) . "\n";

echo "---- FILE EXISTS --------\n";
$path = '/home/luca/Scrivania/file_that_exists.jpg';
echo "File size is: " . filesize($path) . "\n";

echo "---- FILE NOT EXISTS ----\n";
$path = 'file/does/not/exists.jpg';
echo "File size is: " . filesize($path) . "\n";

:

---- NULL ---------------
File size is: 
---- FILE EXISTS --------
File size is: 78953
---- FILE NOT EXISTS ----

Warning: filesize(): stat failed for file/does/not/exists.jpg in /home/luca/Scrivania/test.php on line 13

Call Stack:
    0.0001     642120   1. {main}() /home/luca/Scrivania/test.php:0
    0.0002     642448   2. filesize() /home/luca/Scrivania/test.php:13

,

$_FILES['profile']['name'];

SERVER :

  • ( ), .
  • -,
  • null ( null (. )

PHP-.

UPDATE

Marc B $_FILES['profile']['tmp_name'];

+1

All Articles