File size limitations on multiple file uploading
I started working with multiple images uploading. You open the select file window and you select files while holding CTRL to select multiple files. I got everything to work except a part:
I cannot limit the file size for one image! I cannot figure out how to grab one of the images and compare it with my desired file size (10 MB), if the file size is bigger than 10 MB the user should receive an error, if it's lesser than 10 MB, then continue..
How would I d开发者_JS百科o this? It's quite different with multiple files, not the same as with one file.
Okay, I figured out how to fix this issue the following way. I used a foreach loop for uploading multiple images. I used it this way:
foreach ($_FILES['file']['tmp_name'] as $key => $tmp_name)
Inside the loop I did the following:
$fileSize = $_FILES['file']['size'][$key];
if ($fileSize <= 10485760)
{
// upload code
}
This got this to work ! :D
Hope thi serves anyone in the future...
in php there is standard mechanism that allow to limit fize of uploading files. you just need to add form parmeter MAX_FILE_SIZE and specify size it bytes as its value:
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="file" name="excel_file"/>
</form>
i would recommend taking all the files as an array and then checking for size on each of them, also keep in mind that you should set a max of the number of files that can be uploaded by 1 person at 1 time.
精彩评论