PHP uses apc to implement Upload progress bar _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP uses apc to implement the upload progress bar method. Php itself does not have the real-time Upload progress bar function. if you want this function, we generally use ajax. However, php provides an apc, php itself does not have the real-time Upload progress bar function. if you want this function, we generally use ajax, but php provides an apc, you can configure the upload progress bar with php.

It mainly targets applications on Windows.
1. the server must support apc extension. if this extension is not available, Baidu php_apc.dll should be used to download an extension that requires php.5.2 or later.
2. configure apc and restart apache.

The code is as follows:
Extension = php_apc.dll
Apc. rfc1867 = on
Apc. max_file_size = 1000 M
Upload_max_filesize = 1000 M
Post_max_size = 1000 M

Note: the size of parameters depends on the project's apc. max_file_size: specifies the size of the files that can be uploaded by apc. apc is required. max_file_size <= upload_max_filesize and apc. max_file_size <= post_max_size. restart apache to support apc.
3. use phpinfo () in the code to check whether the apc extension is installed.
4. The following is the implementation code:
Getprogress. php

The code is as follows:

Session_start ();
If (isset ($ _ GET ['progress _ key']) {
$ Status = apc_fetch ('upload _ '. $ _ GET ['SS SS _ key']);
Echo ($ status ['current']/$ status ['total']) * 100;
}
?>
Upload. php

PHP Code
$ Id = $ _ GET ['id'];
?>

Target. php

The code is as follows:
Set_time_limit (600 );
If ($ _ SERVER ['request _ method'] = 'post '){
Move_uploaded_file ($ _ FILES ["test_file"] ["tmp_name"],
Dirname ($ _ SERVER ['script _ filename']). "/UploadTemp /". $ _ FILES ["test_file"] ["name"]); // The UploadTemp folder is located in the same directory as the script.
Echo"

Uploaded

";
}
?>

Index. php

The code is as follows:

$ Id = md5 (uniqid (rand (), true ));
?>

Upload progress

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.