Skip to content
Advertisement

php file size validation

I would like to create in php file size validation for every single file. I used for loop to add attachments, and then created condition to check file, but it’s not working. There’s no error, but it send mail with oversized attachment, instead of stop. Without the size validation part, it sends mail without any problems.

For sending I used php mailer.

JavaScript

I have rebuilt my code a bit, and also complied with comments/clues.

But there’s still the same problem.

Advertisement

Answer

This is a copy paste error

JavaScript

According to the PHP documentation, size is under $_FILES['uploaded-file'] and not $_FILES['uploaded-file']['name']. See @yuxufabio’s comment.

And the if (isset($attachments)) check is a bit weird. It’ll always return an array (meaning true) even if it’s empty. What you probably mean is if the form variable itself is set or not

JavaScript

Lastly, you should be checking if there’s an error, as the upload is not garuanteed to work at the fault of the client, such as an empty file or a network error

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement