0

I'm using this simple code to catch the file size:

$photoSIZE = filesize($_FILES['photo']['name']);
$attachSIZE = filesize($_FILES['attach']['name']);

i receive the error:

filesize() [function.filesize]: stat failed 

i uploaded a 21mb file

what should be?

1 Answer 1

1

You don't need to call filesize(), you can get the size of uploaded files as follows:

$photoSIZE = $_FILES['photo']['size'];
$attachSIZE = $_FILES['attach']['size'];

Alternatively, you can use filesize() as you did but you have to do it on the tmp_name var which holds the path of the uploaded file, as follows:

$photoSIZE = filesize( $_FILES['photo']['tmp_name'] );
$attachSIZE = filesize( $_FILES['attach']['tmp_name'] );

Take a look at the PHP file upload documentation for more info on these variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.