Use the php extension module APC to upload large files

Source: Internet
Author: User
Tags apc apc module
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.

";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.