Jump to content

How to limit what files can be uploaded?


Tuskony

Recommended Posts

Hey guys,

 

I have a form where people can upload up to 5 images. I have it down so you can only upload images etc.

 

But the issue I am having is that if a user uploads a file that's too big, or of the wrong type (IE Not a picture) it is actually uploaded to the file server THEN determined it's invalid.

 

Is there anyway I can get the browser to limit what size of files will even be attempted to get uploaded?

 

I hope this makes sense!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/154458-how-to-limit-what-files-can-be-uploaded/
Share on other sites

You can never control what the browser does.  But php has a directive that will refuse any file larger than a particular size.  You can read about it here: http://www.php.net/manual/en/features.file-upload.post-method.php

 

If you use that, the upload will be rejected before your script deals with it.

 

There is an advisory method you can use to request the browser doesn't upload anything larger than a certain size, which is also mentioned on that page.  But you can't control if that is followed or not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.