Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a problem when attempting to upload really big files using PHP. I know this has been raised before and I have read many responses, but I have not found a definitive answer.

The basic code I use is posted here: http://design.wildsandwebdesign.co.uk/technical/uploading-files-2.php and I have used this with complete success for letting client upload image files, JPEG, GIF, png etc. The problem arose in allowing users to upload non-displayable files such as .psd files which can be very large.

In php.ini on both my local and remote servers upload_max_filesize and post_max_size are set to 128MB. The hidden field MAX_FILE_SIZE in the code has been set to various values during development. The problem is this: If the user selects a file bigger than the MAX_FILE_SIZE but smaller than 128MB,$_FILES['uploadfile']['error'] returns an error code of 2 as the PHP documentation says it will. If the file size exceeds 128MB then the upload handling fails altogether with bizarre results.

The “bizarre” results include irrelevant error messages such as “Undefined index: uploadbtn” this being the index of the submit button you have to click to get the error message(!) This happens with Firefox 26 and with Chrome. Bigger files can crash Firefox altogether which then displays the bug report dialog.

I don't want to upload files larger than 128MB, I just want to handle the situation where a user selects a very large file in some reasonable way. Does anyone know how to do this?

The production code is very much more complicated than the example above but I will happily provide it on request.

......

share|improve this question
    
Why not put the MAX_FILE_SIZE at 128 MB and validate with AJAX the field with $_FILES['filename']['size'] comparing it with a variable set by you $max_file_size = <<value you want it to be max>> and return an error if it's bigger than that – Arrok Feb 4 '14 at 14:04
    
The processing code does not run at all, debug code cannot retrieve any values from the $_FILES array when the selected file is > 128MB and I suspect it may not be created at all, but I will certainly follow this up. Thanks. – user2190783 Feb 5 '14 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.