When uploading multiple files, we may often need a long wait time, and the network and software, and so on, often have time-out and upload failure phenomenon. How to get the file upload progress in real time when uploading multiple files in PHP, and how to avoid PHP and other factors to upload files of any size?
- Experience Summary: Sample PHP Upload file code
- Five-minute resolution PHP upload file code Demo
- Mining php Upload File type principle implementation
- Three-step FTP implementation of PHP upload file code Analysis
- Two types of PHP upload file size limit solution
PHP and other languages such as ASP to the upload file processing method, ASP can use Request.BinaryRead streaming read the data submitted by the client. PHP is to store files in a temporary folder, and after the file upload is complete, you can obtain information and manipulate it. If we can get the file name of the temporary file during the uploading process, we can get the upload progress by judging the size of the temporary file, but there seems to be no way to get it. So we can only use the PHP socket extension to build a simple server, post the data to this server, and then use our own mechanism to deal with.
First talk about the process, first use the PHP socket library to establish a temporary HTTP server, at one end of the port listening, and then the IP address and port number to notify the client, the client Upload form submission (temporary server), the temporary server to accept the client request, and read the post data, Analyze and obtain the file information uploaded by the client, save the file on the server, then close the temporary server, release the resources, upload the complete. A bit around, but the idea is still simple.
Later I will publish a class library, tentatively named: Ugia Visual PHP Uploader, so that everyone can be very convenient to call in the program. PHP uploads multiple file effects as follows:
the APC implementation method for uploading multiple files in PHP :
Install APC, refer to the Official document installation, you can use the Pecl module installation method quick and simple, here does not explain the configuration php.ini, set the parameters apc.rfc1867=1, so that APC support the upload progress bar function, in the APC source code documentation, there is a description of the codes example:
- if ($_server[' request_method ' = = ' POST ') {//Upload request
- $ Status = Apc_fetch (' Upload_ '. $_post[' apc_upload_progress ');
- $status [' done '] = 1;
- echo Json_encode ($status); Output to Ajax calls in the user-side page, please find the relevant documents yourself
- Exit
- } elseif (Isset ($_get[' Progress_key ')) {//Read upload Progress
- $ Status = Apc_fetch (' Upload_ '. $_get[' Progress_key ');
- echo Json_encode ($status);
- Exit
- } else {
- Other code, such as uploading a form, etc.
- }
uploadprogress Module Implementation Method :
- Install the module using the PECL module installation method php.ini inside the setup uploadprogress.file.filename_template = "/tmp/upd_%s.txt" code example:
- if ($_server[' Request_method ']== ' POST ') {
- if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {
- $ Upload_dir = ' your_path/' ;
- $ ext = STRRCHR ($_files[' video ' [' Name '], '. ');
- $ sessid = $_post[' Upload_identifier '];
- $ tmpfile = $upload _dir. $sessid;
- $ Sessfile = $upload _dir. $sessid. $ext;
- if (Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $tmpfile)) {
- Upload successful
- } else {
- Upload failed
- } else {
- Upload Error
- } elseif (!empty ($_get[' sessid ')) {
- Header ("Expires:mon, Jul 1997 05:00:00 GMT");
- Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");
- Header ("Cache-control:no-store, No-cache, must-revalidate");
- header ("Cache-control: post-check=0, pre-check= 0", false);
- Header ("Pragma:no-cache");
- header ("content-type:text/html; CharSet = UTF -8 ");
- $ unique_id = $_get[' sessid '];
- $ uploadvalues = Uploadprogress_get_info ($unique _id);
- if (Is_array ($uploadvalues)) {
- echo Json_encode ($uploadvalues);
- } else {
- Read progress failed, additional processing logic
- }
- } else {
- Show Upload Form
http://www.bkjia.com/PHPjc/588982.html www.bkjia.com true http://www.bkjia.com/PHPjc/588982.html techarticle when uploading multiple files, we may often need a long wait time, and the network and software, and so on, often have time-out and upload failure phenomenon. How to upload in PHP ...