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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top