I am trying to get the file size of an image and I keep getting Warning: filesize(): stat failed for img.jpg
This is what I did:
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";
Would result in:
---- 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
This means that your variable
$_FILES['profile']['name'];
is NOT pointing to a valid file location on the SERVER and is instead one among:
null (see first example)Please next time post valid PHP code.
Luca
UPDATE
As Marc B suggested you have to use $_FILES['profile']['tmp_name'];