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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.