Php+apc+ajax implementation of Ajax_upload upload progress bar code, ajaxajax_upload_php tutorial

Source: Internet
Author: User
Tags apc apc module file upload progress bar php file upload

Php+apc+ajax implementation of the Ajax_upload upload progress bar code, Ajaxajax_upload


The example of this paper describes the Ajax_upload upload progress bar code implemented by Php+apc+ajax. Share to everyone for your reference, as follows:

How does the upload progress bar work? How does the principle work? When we browse, select Upload, will generate a temporary file, upload the temporary file, uploaded to the server, upload completed, the temporary file will be deleted. If we can read the size of this temporary file, we know the upload progress is how much, the PHP APC module can implement this function.

First, install the APC module

Download Address: HTTP://PECL.PHP.NET/PACKAGE/APC

Tar zxvf apc-3.1.8.tgzcd apc-3.1.8//usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/ Php-configmake && make Install

Ii. Modification of PHP.ini

Extension = apc.soapc.rfc1867 = 1apc.max_file_size = 200mupload_max_filesize = 1000mpost_max_size = 1000mmax_execution_ Time = 600max_input_time = 600memory_limit = 128M

After modification, re-start Apache or other, check

[Root@blackghost php]# php-m[php modules]apccgi-fcgictypecurldatedomeaccelerator ...

Third, upload_test.php

<?php$id = Uniqid (rand (), true);? >

Upload Test




Apc_upload_progress What's the use of this? It adds a tag to the uploaded file, and it can be accessed using this tag in other PHP programs. Provides support for the read of APC.

Upload.js asynchronous upload of JS file:

function Form_submit () {New Ajaxupload (' #upload ', {action: ' upload.php ', Name: ' File ', data: {APC_ upload_progress:$ ("#progress_key"). Val ()},autosubmit:true,onsubmit:function (file, extension) {$ (' #progressouter ' ). CSS (' Display ', ' block ');p rogress ();},oncomplete:function (file, response) {$ ("#showInfo"). HTML (response);}});} function Progress () {$.ajax ({type: "GET", url: "progress.php?progress_key=" +$ ("#progress_key"). Val (), DataType: "JSON ", cache:false,success:function (data) {if (data = = 0) {var precent = 0;} else {for (i-data) {if (i = = "current") {var json_current = parseint (Data[i]);} if (i = = "Total") {var json_total = parseint (Data[i]);}} var precent = parseint (Json_current/json_total *), $ ("#progressinner"). CSS ("width", precent+ "%"); $ ("#showNum"). HTML (precent+ "%"); $ ("#showInfo"). html ("OK");} if (Precent <) {SetTimeout ("Progress ()", +);}});} 

It is important to note that apc_upload_progress:$ ("#progress_key"). Val () Here, key is apc_upload_progress if this is not the case, APC cannot find the temporary file. Why do I use ajax_upload.js here, because jquery comes with Ajax, the parameters do not upload files, that is, the content of type= ' file ', PHP is not available at all.

Iv. upload.php Uploading files

<?phpif ($_server[' request_method ') = = ' POST ') {if (Empty ($_files["file"] ["Tmp_name"]) {echo "no file";d ie;} $tmp _name = $_files["File" ["Tmp_name"]; $name = dirname ($_server[' script_filename ']). " /upload/". $_files[" File "[" Name "];move_uploaded_file ($tmp _name, $name); echo"

File uploaded.

";}? >

If the file is relatively large, do not use HTTP to upload, too slow, and affect the stability of the site.

V. progress.php the progress of the file, for Ajax calls with the

<?phpif (Isset ($_get[' Progress_key ')) {$status = Apc_fetch (' upload_ '. $_get[' Progress_key ']); if ($status [' Total ' ]!=0 &&!empty ($status [' total ']) {echo json_encode ($status);} else {echo 0;}}? >

Look at the data generated by the Ajax asynchronous request.

PHP APC Ajax upload progress bar

Parameter description:

Total File Size
Current uploaded size
FileName Upload file name
Name label Signature
Done upload succeeded to 1
Cancel_upload the user cancels the upload, only when the upload is complete.
Rate upload speed, only when the upload is complete
Start_time Start time

Read more about PHP files and AJAX operations related content readers can view this site topic: "PHP file Operation Summary" and "Php+ajax Tips and Application Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • PHP implements a simple upload progress bar
    • PHP using APC module to implement large file upload progress bar method
    • PHP's APC module implements the upload progress bar
    • PHP implements real-time upload progress bar function with APC
    • How PHP Implements file upload progress bar using APC module
    • PHP using session with JavaScript to implement the file Upload progress bar function
    • Problem resolution using PHP+APC to implement upload progress bar and not display under IE7
    • PHP File Upload progress bar Two implementation methods of the Code
    • Php+flash Implement upload file progress bar related file download
    • PHP with jquery plugin ajaxfileupload implementation of asynchronous upload file instances
    • Php+ajax upload Image instance code without refresh
    • Php+jquery+ajax achieve multi-image upload effect

http://www.bkjia.com/PHPjc/1095682.html www.bkjia.com true http://www.bkjia.com/PHPjc/1095682.html techarticle Php+apc+ajax Implementation of the Ajax_upload upload progress bar code, Ajaxajax_upload This example describes the Php+apc+ajax implementation of the Ajax_upload upload progress bar code. Share to everyone for your reference, ...

  • 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.