PHP Upload progress bar method with APC implementation

Source: Internet
Author: User
Tags apc apc configuration php code php upload progress bar

The main target is the application on window.
1. The server to support APC expansion, without this extension, Baidu click Php_apc.dll, download an extension of expansion requirements php.5.2 above.
2. Configure APC configuration, restart Apache

The code is as follows Copy Code
Extension=php_apc.dll
apc.rfc1867 = On
Apc.max_file_size = 1000M
Upload_max_filesize = 1000M
Post_max_size = 1000M

Explain: As for the parameters to match how big, need to see the project needs apc.max_file_size, set up APC support upload file size, request Apc.max_file_size <=upload_max_filesize and Apc.max_ File_size <=post_max_size. You can implement APC support by restarting Apache.
3. Use Phpinfo () in the code to see if the APC extension is installed.
4. Here is the implementation code:
getprogress.php

The code is as follows Copy Code

<?php
Session_Start ();
if (Isset ($_get[' Progress_key ')) {
$status = Apc_fetch (' upload_ '. $_get[' Progress_key '));
Echo ($status [']/$status [' Total ']) *100;
}
?>
upload.php

PHP Code
<?php
$id = $_get[' id '];
?>
<form enctype= "Multipart/form-data" id= "Upload_form" action= "target.php" method= "POST" >
<input type= "hidden" name= "apc_upload_progress"
Id= "Progress_key" value= "<?php echo $id?>"/>
<input type= "File" id= "Test_file" name= "Test_file"/><br/>
<input onclick= "window.parent.startProgress (); return true; "
Type= "Submit" value= "Upload"/>
</form>

target.php

The code is as follows Copy Code
<?php
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"]);//uploadtemp folder is located in the same directory as this script
echo "<p> upload success </p>";
}
?>

index.php

The code is as follows Copy Code

<?php
$id = MD5 (Uniqid (rand (), true);
?>
<body>
<script src= "Js/jquery-1.4.4.min.js" language= "JavaScript" ></script>


<script language= "JavaScript" >
var pronum=0;
var loop=0;
var Progressresult;
function Sendurl () {
$.ajax ({
Type: ' Get ',
URL: "getprogress.php?progress_key=<?php echo $id;? > ",
Async:true,
Cache:false,
DataType: ' JSON ',
Data: "progress_key=<?php echo $id;? > ",
Success:function (e) {
Progressresult = e;
Pronum=parseint (Progressresult);
document.getElementById ("Progressinner"). Style.width = pronum+ "%";
document.getElementById ("Shownum"). InnerHTML = pronum+ "%";
if (Pronum < 100) {
SetTimeout ("getprogress ()", 100);
}

}
});

}

function getprogress () {
loop++;

Sendurl ();
}
var interval;
function startprogress () {
document.getElementById ("Progressouter"). style.display= "Block";
SetTimeout ("getprogress ()", 100);
}
</script>
<iframe id= "Theframe" name= "Theframe"
Src= "upload.php?id=<?php echo $id;?>"
Style= "Border:none; height:100px; width:400px; ">
</iframe>
<br/><br/>
<div id= "Progressouter" style= "width:500px; height:20px; BORDER:6PX solid red; Display:none; " >
<div id= "Progressinner" style= "position:relative; height:20px; Background-color:purple; width:0%; "></div>
</div>
<div id= ' Shownum ' ></div><br>
<div id= ' showNum2 ' ></div>
</body>

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.