简体   繁体   中英

how to upload a large size file in chunks on server in php?

How do I divide a large file in chunks and upload it to server?

I try the simple move_uploaded_file() function but it upload only of 2 MB size.

increase upload maximum file size limit with this method :

Method # 1: Edit php.ini

Edit your php.ini file (usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):

# vi /etc/php.ini

Sample outputs:

memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M

Save and close the file. Restart apache or lighttpd web server:

service httpd restart

OR service lighttpd restart

Method #2: Edit .htaccess

Edit .htaccess file in your root directory. This is useful when you do not have access to php.ini file. In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):

# vi /home/httpd/html/.htaccess

Append / modify setting as follows:

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

Save and close the file.

Method #3: Edit PHP File

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

After this you can ckeck :

<?php
   phpinfo();
?>

check this for chunk upload plupload

This is a class that can help you to chunk big files using pattern strings and reassemble them at server level.

The class

As you don't mention what file format you are talking about the class will need some tweaking and testing for you to work.

try putting this code top of 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);

You can actually update your php ini to allow uploading larger files

Maximum allowed size for uploaded files.
upload_max_filesize = 100M;

Must be greater than or equal to upload_max_filesize
post_max_size = 100M;

But if you still need to upload huge files and chunking is a mandatory, there are lots of javascript implementation for this, one of them:

http://www.plupload.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM