Using .htaccess, is it possible to restrict the php file upload size limit based on type of file ?
For example, the maximum upload limit for images is 2 MB and maximum upload limit for PDF and DOC is 10 MB.
You can make use of the LimitRequestBody directive to limit upload file size. The value assigned to the LimitRequestBody allows Apache to accept and store file uploads of 9000 bytes by users.
I would use the LimitRequestBody directive for this. However, to quote:
Implementations of the
PUT
method will require a value at least as large as any representation that the server wishes to accept for that resource.
You can set this to 10Mb to have Apache cut off any request which is surely too large, and then further test and filter within your script. This directive is mostly used to prevent denial-of-service attacks. Without this directive, Apache will gladly accept the entire file before it ever reaches your script, so users could be uploading 100Gb files before being told that it's too long.
This directive will not peek into the body of the request, though, so you can't filter on file type with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With