-2

I'm trying to set some kind of max value for the size of the files that gets uploaded to my PHP-server, but I can't find anything that works.

I've tried using the "<input type="hidden" name="MAX_FILE_SIZE" value="30000">"-method in my form, but that does not seem to do anything. I've also tried checking the size after it's uploaded, by doing something like: "if($_FILES["file"]["size"]/1024 > 10240){". And of course, that doesn't work either, since the file has already been uploaded by then and has crashed my server before that check happens.

I've searched a lot for ways of doing this, and all I could find was sites saying that the "<input type="hidden" name="MAX_FILE_SIZE" value="30000">" is the way, and some saying that it is the way, but that it doesn't work at all. So I'm very confused at the moment. But I've tried these two methods, and none of the work, and I'm unable to find a third option. So please help me!

Edit: I think this question is different from other questions on a similar subject since I'm asking for a way of having the server detect that the file is too big without crashing the server, which it does when the size is specified only in php.ini. I want to be able to detect that the file is too big, send a pretty "your file is too big, try again", and then direct the user back to the upload site (the directing part I know how to do). Is that possible?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jonatan Stenbacka
  • 1,824
  • 2
  • 23
  • 48
  • Define it in `php.ini` or `.htaccess` – Funk Forty Niner May 13 '14 at 17:24
  • "the file has already been uploaded by then and has crashed my server" sounds like your server needs fixing. – Sammitch May 13 '14 at 17:31
  • Check your logs then. – Funk Forty Niner May 13 '14 at 17:32
  • Well I can define it in php.ini or .htaccess, and I have. But that still just makes my server "crashes" and I get a "Warning: POST Content-Length of 786614735 bytes exceeds the limit of 8388608 bytes in Unknown on line 0". And that isn't too pretty. Isn't there a way to check the size and somehow prevent the server from crashing, and then just send a pretty little message like "Sorry your file is to big"? – Jonatan Stenbacka May 14 '14 at 11:50

1 Answers1

1

you can use these two php.ini settings:

post_max_size = 10M
upload_max_filesize = 10M
Scott Jungwirth
  • 6,105
  • 3
  • 38
  • 35