No error when uploading a really big file in PHP?

后端 未结 6 772
说谎
说谎 2021-02-06 18:14

I have a PHP form for uploading files and it works fine and displays an error message if something went wrong. This is all good.

The problem is when I test with a really

相关标签:
6条回答
  • 2021-02-06 18:27

    I would implement a simple script that does regular ajax calls to know how much of the upload has been done. You can then implement some sort of progress bar. There are a couple of examples on the net:

    http://martinjansen.com/2007/04/28/file-upload-progress-bars-with-php/

    0 讨论(0)
  • 2021-02-06 18:28

    Your $_POST is most likely empty because the upload exceeded the post_max_size directive:

    From PHP's directives page:

    If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

    0 讨论(0)
  • 2021-02-06 18:35

    you can not know the size of the file that is being uploaded, until it gets fully uploaded. so if you want to determine the file size, and then show an error for large files, first you must have the file uploaded, then check the file size. inorder to have a large file uploaded, you should set 2 settings in your php configuration file, php.ini. open it up and search for "upload_max_filesize" and set the value to maximum value you want. then you must set the maximum value for POST parameters, because uploaded files are recieved via HTTP POST method. find "post_max_size" and set it to a large value to.

    0 讨论(0)
  • 2021-02-06 18:42

    apart form the options as the former users answered:

    max upload filesize (upload_max_filesize)
    max post data size (post_max_size)
    memory limit (memory_limit)
    

    there is also one, when the file is very large, or the line is busy, there need to much time to execute this operation, which will hit to ceil of the script execution limit.

    max_execution_time
    
    0 讨论(0)
  • 2021-02-06 18:46

    Check your PHP ini file, which governs how large a file PHP will allow to be uploaded. These variables are important:

    • max upload filesize (upload_max_filesize)
    • max post data size (post_max_size)
    • memory limit (memory_limit)

    Any uploads outside these bounds will be ignored or errored-out, depending on your settings.

    This section in the docs has the best summary: http://ca3.php.net/manual/en/features.file-upload.common-pitfalls.php

    EDIT: Also note that most browsers won't send uploads over 2GB in size. This link is outdated, but gives an idea: http://www.motobit.com/help/scptutl/pa98.htm. Anyone have a better source of info on this?

    There are also limits that can be imposed by the server, such as Apache: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody

    To truly see what's going on, you should probably check your webserver logs, check the browser upload limit (if you're using firefox), and try seeing if print_r($_FILES) generates any useful error numbers. If all else fails, try the net traffic monitor in firebug. The key is to determine if the request is even going to the server, and if it is what the request (including headers) looks like. Once you've gotten that far in the chain, then you can go back and see how PHP is handling the upload.

    0 讨论(0)
  • 2021-02-06 18:49

    max upload filesize (upload_max_filesize) max post data size (post_max_size) are the directives you need to set. I have tested it with multiple OS, browsers etc and these are the only two thing you need be worried about.

    0 讨论(0)
提交回复
热议问题