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:
$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 am able to get the file extension no problem but the filesize()
just doesn't seem to work. I have been reading a bit and did find this but it did not solve the problem. Any help is much appreciated!
Would result in:
This means that your variable
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'];
['name']
in the $_FILES array is the name of the file on the CLIENT machine. It is information only, and has absolutely no relevance to what's actually stored on your server. You need to look at['tmp_name']
, which is where PHP has stored the file temporarily on the server, after the upload completed:$_FILES['profile']['name']
has just name of the file.. you need to accesswill give you the temporary path of the file on your system. Here is http://php.net/manual/en/reserved.variables.files.php
also you can access size of file with