How to check file size in PHP before uploading to temp folder?
Get the solution ↓↓↓How do I verify that a file isn't too big to upload in php before uploading it to the temp folder?
This line:
if ($_FILES['file']['size'] <= 10485760)
will not work because the file gets uploaded to the temp directory first. I already have an Ajax solution that works perfectly. I am trying to code for when scripting is disabled.
According to php.net I can prevent a user from having to wait for a file to upload before receiving an error message stating that it's too big by using this line:
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
but that does not work. All it does it change the maximum file size to 30000.
Answer
Solution:
As users have stated in the comments, this cannot be done in PHP. The PHP manual is wrong, as it clearly states I can prevent a user from having to wait for the upload to complete before giving them an error because the files too big by using this line:
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
In future, I won't usephp.net
as a reference. I'll just stick to using Stack Overflow.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: regex stop at first match
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.