My environment is Windows. I need to download the php_apc.dll file, put php_apc.dll into php/ext, and add the following statement to php. ini. I. installation and configuration of APC module
My environment is Windows. you need to download the php_apc. dll file, put php_apc.dll in php/ext, and add the following statement to php. ini:
Extension = php_apc.dll
Apc. rfc1867 = 1
Apc. max_file_size = 200 M
In addition, because you need to upload a large file, you need to change the following options in php. ini:
Upload_max_filesize = 1000 M
Post_max_size = 1000 M
Max_execution_time = 600; maximum time (in seconds) for running each PHP page. the default value is 30 seconds.
Max_input_time = 600; maximum time required for receiving data on each PHP page. the default value is 60 seconds.
Memory_limit = 128 M; maximum memory consumed by each PHP page. the default value is 8 M.
2. get the progress bar code
Getprogress. php
Session_start (); If (isset ($ _ GET ['progress _ key']) { $ Status = apc_fetch ('upload _ '. $ _ GET ['SS SS _ key']); If ($ status ['total']! = 0 &&! Emptyempty ($ status ['total']) { Echo json_encode ($ status ); } Else { Echo (0 ); } } ?> Session_start (); If (isset ($ _ GET ['progress _ key']) { $ Status = apc_fetch ('upload _ '. $ _ GET ['SS SS _ key']); If ($ status ['total']! = 0 &&! Empty ($ status ['total']) { Echo json_encode ($ status ); } Else { Echo (0 ); } } ?> |
Json is used for data transmission.
$ Status object is an array with the following fields:
Total: total file size
Current: number of files received so far
Rate: the upload speed (in bytes/s). However, it is only available after the upload is complete.
Filename: file name
Name: variable name
Temp_filename: the location where PHP saves the temporary copy of the file
Cancel_upload: the upload has been canceled (1) or not (0)
Done: The upload has been completed (1), or has not been completed (0)
Here, we use json to upload all the data to the page for later use.
3. main file
Upload. php
$ Id = md5 (uniqid (rand (), true )); ?> Upload Example
"Width: 500px; height: 20px; border: 1px solid black; display: none;"> "Position: relative; height: 20px; background-color: gray; width: 0%;">
$ Id = md5 (uniqid (rand (), true )); ?> Upload Example
"Width: 500px; height: 20px; border: 1px solid black; display: none;"> "Position: relative; height: 20px; background-color: gray; width: 0%;">
|
Here, the following code restores the received json string:
// Parse the status so that the object can be obtained using json. something.
Var json = eval ("(" + status + ")");
Json_current = parseInt (json. current );
Json_total = parseInt (json. total );
// Parse the status so that the object can be obtained using json. something.
Var json = eval ("(" + status + ")");
Json_current = parseInt (json. current );
Json_total = parseInt (json. total );
IV. receiving and saving uploaded files
Target. php
Set_time_limit (600 ); If ($ _ SERVER ['request _ method'] = 'post '){ Move_uploaded_file ($ _ FILES ["upload_file"] ["tmp_name"], Dirname ($ _ SERVER ['script _ filename']). "/UploadFiles/". $ _ FILES ["upload_file"] ["name"]); Echo"File uploaded. "; } ?> |