Jump to content

Limiting size of uploaded file through <input type='file' ....


Recommended Posts

Hi all,

 

 

Sorry if this is a very obvious question - I had a search through but couldn't find any answers, but this feels like it should be obvious.

 

I have a script running on a site I'm working on that does a very standard file upload - i.e. there's a standard form with an <input type='file' ... element that uploads the file. I can then access it through PHP using the $_FILES superglobal, and ultimately I then stick the files content, type, size and name in a MySQL database.

 

Which is great.

 

What I want is to be able to limit the size of a file that user can upload. Without a limit many users are just going to exceed my php.ini settings and thus see an ugly php error message (I don't have access to the php.ini file, I'm on a hosted server for our company, and our host doesn't even seem to allow iniset() overrides).

 

I know that can easily check the size of the uploaded file server-side with php as one of the $_FILE properties, but the trouble is that in order to do that the file must first have been uploaded to the server, which doesn't help me.

 

There's probably a javascript way of doing it, but then whats to stop someone without JS (or with JS disabled) from uploading a big file anyway.

 

So, any ideas how to stop someone trying to stick a 10MB file on my upload form and being greeted witha PHP error message? Any ideas welcome.

 

 

Thanks,

 

Me.

 

Link to comment
https://forums.phpfreaks.com/topic/105479-limiting-size-of-uploaded-file-through/
Share on other sites

By using some error checking logic in your upload form processing code, you can detect if the upload worked and avoid the generation of error messages.

 

To start with, you would need to post the error message you are talking about. You would also need to post your code.

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.