开发者

What's the difference in these ways of determining uploaded file size in PHP?

开发者 https://www.devze.com 2023-03-12 00:10 出处:网络
I came across this piece of code where programmer determines uploaded file size like this开发者_如何学Go:

I came across this piece of code where programmer determines uploaded file size like this开发者_如何学Go:

$file_size = @filesize($_FILES[$upload_name]["tmp_name"]);

AFAIK one can simply do:

$_FILES[$upload_name]["size"];

Are there reasons to use filesize() function over reading file size from $_FILES array?


$_FILES[$upload_name]["size"]

This is populated for you by PHP after receiving the uploaded file.

$file_size = @filesize($_FILES[$upload_name]["tmp_name"]);

This is a wasteful method that goes out and gets the file size from the drive, even though it's already populated inside $_FILES[$upload_name]["size"].

0

精彩评论

暂无评论...
验证码 换一张
取 消