Problem with uploading large files in PHP

Asked

Viewed 8,451 times

2

I’ve already set my site’s php settings to upload limit size (post_max_size and upload_max_filesize). I put 1 Giga as a precaution for testing.

But when I try to upload a 30 megas file, the status bar shows the progress of the upload and I noticed that the browser tries to upload twice and then falls on an error page of the browser itself.

The upload always drops in different percentages, so I guess it’s no problem with space limits. And files up to 5 megas are being loaded normally without errors.

I normally perform ftp uploads of larger files.

Is this because of server instability? How does this process work and how do I control it? There is a way I persist more than 2 times the upload?

UPDATING

Answering the question, the server is apache. And the error time is 1 minute. In php info I looked for the number 60 (to see some 60-second timeout configured) and changed all I found for more. The error persists.

Follow my php settings:

[PHP]
asp_tags = On
include_path = ".:/usr/share/pear"
ignore_repeated_source = Off
variables_order = "EGPCS"
track_errors = On
output_buffering = 4096
doc_root = 
log_errors = On
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
auto_append_file = 
disable_classes = 
enable_dl = Off
display_startup_errors = Off
user_dir = 
extension_dir = "/usr/lib/php/modules/"
register_argc_argv = On
display_errors = On
allow_call_time_pass_reference = Off
safe_mode_exec_dir = 
default_socket_timeout = 1000000000
register_globals = On
unserialize_callback_func = 
y2k_compliance = On
magic_quotes_runtime = Off
expose_php = Off
log_errors_max_len = 1024
report_memleaks = On
engine = On
memory_limit = 640000000000M
short_open_tag = On
upload_tmp_dir = /home/storage/0/be/ca/johny2/tmp
max_execution_time = 6000000000000000
safe_mode_include_dir = 
serialize_precision = 100
precision = 14
register_long_arrays = On
safe_mode = Off
zend.ze1_compatibility_mode = Off
zlib.output_compression = Off
ignore_repeated_errors = Off
default_mimetype = "text/html"
disable_functions = 
file_uploads = On
magic_quotes_sybase = Off
max_input_time = 6000000000000
magic_quotes_gpc = Off
error_reporting = E_ALL & ~E_NOTICE
safe_mode_gid = Off
auto_prepend_file = 
implicit_flush = Off
allow_url_fopen = On
upload_max_filesize = 1000000000000M
post_max_size = 100000000000000M
  • 1

    What is the error code of the browser, or message?

  • "This web page is not available". My upload php page is in the url, but a default browser error page opens.

  • Can be script execution timeout. Already tried set_time_limit?

  • I tried set_time_limit but it didn’t work either.

  • 2

    The server is apache or IIS?

  • 1

    Are you sure the configs are being applied? Take a look at phpinfo(). There is a chance that configs defined in ini are being overwritten elsewhere (php or htaccess file).

  • 1

    I don’t know which server, but if Apache, take a look at the value of LimitRequestBody. If the file exceeds this value, it may be locked even before it reaches PHP. Link to the documentation.

  • Just to clarify, the size of files sent by PHP upload/post have no relation to those sent via FTP.

Show 3 more comments

3 answers

3

Configure this information in your PHP.ini:

upload_max_filesize 10M
post_max_size 10M
max_input_time 300
max_execution_time 300

Then set the constants in your code:

ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);

Detail, always check by phpinfo(); if the information you are setting in php.ini is being applied, it is very common to set in the wrong php.ini.

Then this way you move up your file:

$name = 'arquivogrande.zip';

header("Content-Type: application/zip");
header("Content-Length: " . filesize($name));

readfile($name);
exit;

If you keep running out of time, use the function set_time_limit ( temposegundos) to increase PHP running time.

That should be enough.

1


Going to the support of my hosting provider found that my server is shared and so it had blocks to upload larger files. It wasn’t my configuration’s problem.

0

You should edit in your file php.ini the two variables: post_max_size and upload_max_filesize in the standard PHP syntax format.

Example:

post_max_size = 100M

upload_max_filesize = 100M
  • Thank you friend, but these two variables were the ones I mentioned at the beginning of the question and are already due.

  • 1

    @Joaopaulo, Try then: default_socket_timeout

  • I tried, but it didn’t work.

  • @Joaopaulo, when something like this happens, difficult to identify, I try to time, see the time spent from the beginning of the upload until the moment it is stopped, see if it is the same

  • put the upload PHP code to see how it is done.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.