質問

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