php 上的 upload file

最後更新: 2015-11-10

 

 


System Configuration

 

 - Disable user quotas, which makes them unlimited
 - Your temp file or partition has to be big enough to hold multiple parallel uploads from multiple users;

* upload limit ~ 2G

php.ini setting:

file_uploads = On
upload_max_filesize=8G
post_max_size=10G
memory_limit=512M

# the script is allowed to receive input;
max_input_time

# The time a script is allowed to run after its input has been parsed.
max_execution_time
default_socket_timeout

# Default: /tmp
# tmp filename: php<ID>
upload_tmp_dir = /path/to/somewhere/with/some/disk/space

# mb_substr() is called instead of substr() if function overloading is enabled.
# port applications that only support single-byte encodings to a multibyte environment
mbstring.func_overload=0

# With output buffering, your HTML is stored in a variable and sent to the browser
# as one piece at the end of your script.
# 限制: will disable header modifications (redirects or content-type ..)
# i.e. <?php header("Location: http://www.php.net"); ?>
output_buffering=0


always_populate_raw_post_data=-1
default_charset='UTF-8'

It's important to realize that upload_max_filesize is the sum of the sizes of all the files that you are uploading.

post_max_size is the upload_max_filesize plus the sum of the lengths of all the other fields in the form plus any mime headers that the encoder might include.

(Since these fields are typically small you can often approximate the upload max size to the post max size.)

 


Testing Code

 

[1]

<?php
if (!empty($_FILES)) {
    echo '<pre>';
    var_dump($_FILES);
    echo '</pre>';
}
?>
<form enctype="multipart/form-data" method="POST">
    File: <input name="userfile" type="file" />
    <input type="submit" value="Upload" />
</form>

 


Apache Settings

 

The apache webserver has a LimitRequestBody configuration directive that restricts the size of all POST data regardless of the web scripting language in use.

The body of a request (POST) is normally* limited by the server on a byte size basis in order to prevent a type of DoS attack.

LimitRequestBody (Apache) > memory_limit (php) > post_max_size(php) > upload_max_filesize(php) 才可以

<----------------------------------------- max_execution_time --------------------------------------------->

max_file_uploads integer

    The maximum number of files allowed to be uploaded simultaneously.
   
   
max_input_time integer

    This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. It is measured from the moment of receiving all data on the server to the start of script execution.

ini_set('max_execution_time', 600); // sets it to 10 min (600 sec)

max_input_time can't be changed in scripts, it has to be set in php.ini,
or in httpd.conf or a .htaccess-file

 

.htaccess

php_value upload_max_filesize = 2G
php_value post_max_size = 2G
php_value memory_limit 1G
php_value max_input_time 3600
php_value max_execution_time 3600

 


Upload tools

 

http://fineuploader.com      ( https://github.com/FineUploader/react-fine-uploader )

 


 

Creative Commons license icon Creative Commons license icon