[b]1.APC扩展库的安装(windows);[/b]
(1)首先下载php_apc.dll,然后再php.ini里配置:在扩展库后加(;extension=php_zip.dll)->
extension=php_apc.dll
apc.rfc1867=1
apc.cache_by_default =Off
apc.enable_cli =Off
apc.enabled =On
apc.file_update_protection =2
apc.filters =""
apc.gc_ttl =3600
apc.max_file_size =200M
apc.num_files_hint =1000
apc.optimization =On
apc.shm_segments =1
apc.shm_size =30
apc.slam_defense =Off
apc.stat =On
apc.ttl =0
apc.user_entries_hint =100
apc.user_ttl =0
(2)把php_apc.dll复制到c盘windows文件夹下
(3)重启apache,测试有没安装成功!
if(function_exists("apc_fetch")){
echo "安装成功!";
}
else
{
echo "安装失败,请重新安装!";
}
[b]2.把相关的代码贴上[/b]
[b](1)getprogress.php[/b]
<?php
session_start();
if(isset($_GET['progress_key'])) {
$status =apc_fetch('upload_'.$_GET['progress_key']);
echo ($status['current']/$status['total'])*100;
}
?>
[b](2)upload.php[/b]
<style type="text/css">
*{margin:0px;padding:0px;}
</style>
<?php
$id = $_GET['id'];
if($_GET["add"]=="ok")
{
echo "上传成功!";
}
else{
?>
<form enctype="multipart/form-data" id="upload_form" action="target.php" name="upload_form" 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" οnchange="window.parent.startProgress();" style="width:190px;height:20px; background-color:gray;"/><br/>
</form>
<?php
}
?>
[b](3)progress.php[/b]
<?php
$id = md5(uniqid(rand(), true));
?>
<html>
<head><title>php文件上传进度</title></head>
<body>
<script type="text/javascript">
var xmlHttp;
var proNum=0;
var loop=0;
var Try = {
these: function() {
var returnValue;
for (var i = 0; i < arguments.length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
}
catch (e) {}
}
return returnValue;
}
}
function createXHR(){
return Try.these(
function() {return new XMLHttpRequest()},
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
) || false;
}
var xmlHttp;
function sendURL() {
xmlHttp=createXHR();
var url="getprogress.php?progress_key=<?php echo $id;?>";
xmlHttp.onreadystatechange=doHttpReadyStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function doHttpReadyStateChange() {
if (xmlHttp.readyState == 4){
proNum=parseInt(xmlHttp.responseText);
document.getElementById("progressinner").style.width = proNum+"%";
document.getElementById("showNum").innerHTML = proNum+"%";
if (proNum<100){
setTimeout("getProgress()",500);
}
else
{
window.theframe.location.href='upload.php?add=ok';
}
}
}
function getProgress(){
loop++;
document.getElementById("showNum2").innerHTML = loop;
sendURL();
}
function startProgress(){
document.getElementById("progressouter").style.display="block";
setTimeout("getProgress()",500);
window.theframe.upload_form.submit();
}
</script>
<iframe id="theframe" name="theframe" src="upload.php?id=<?php echo($id); ?>" style=" height:20px; width: 190px;" frameborder="0" scrolling="no">
</iframe>
<div id="progressouter" style="font-size:0px;width:300px;height:5px;border: 1px solid red;display:none;">
<div id="progressinner" style="font-size:0px;position: relative; height:5px; background-color: purple; width:0%;">
</div>
</div><div id='showNum'></div><br>
<div id='showNum2'></div>
</body>
</html>
[b](4)target.php[/b]
<?php
set_time_limit(600);
if($_SERVER['REQUEST_METHOD']=='POST') {
move_uploaded_file($_FILES["test_file"]["tmp_name"],dirname($_SERVER['SCRIPT_FILENAME'])."/upload/" . $_FILES["test_file"]["name"]);//UploadTemp文件夹位于此脚本相同目录下
}
?>
[b]3.打开progress.php进行测试,可以把源码修改成更好的![/b]
(1)首先下载php_apc.dll,然后再php.ini里配置:在扩展库后加(;extension=php_zip.dll)->
extension=php_apc.dll
apc.rfc1867=1
apc.cache_by_default =Off
apc.enable_cli =Off
apc.enabled =On
apc.file_update_protection =2
apc.filters =""
apc.gc_ttl =3600
apc.max_file_size =200M
apc.num_files_hint =1000
apc.optimization =On
apc.shm_segments =1
apc.shm_size =30
apc.slam_defense =Off
apc.stat =On
apc.ttl =0
apc.user_entries_hint =100
apc.user_ttl =0
(2)把php_apc.dll复制到c盘windows文件夹下
(3)重启apache,测试有没安装成功!
if(function_exists("apc_fetch")){
echo "安装成功!";
}
else
{
echo "安装失败,请重新安装!";
}
[b]2.把相关的代码贴上[/b]
[b](1)getprogress.php[/b]
<?php
session_start();
if(isset($_GET['progress_key'])) {
$status =apc_fetch('upload_'.$_GET['progress_key']);
echo ($status['current']/$status['total'])*100;
}
?>
[b](2)upload.php[/b]
<style type="text/css">
*{margin:0px;padding:0px;}
</style>
<?php
$id = $_GET['id'];
if($_GET["add"]=="ok")
{
echo "上传成功!";
}
else{
?>
<form enctype="multipart/form-data" id="upload_form" action="target.php" name="upload_form" 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" οnchange="window.parent.startProgress();" style="width:190px;height:20px; background-color:gray;"/><br/>
</form>
<?php
}
?>
[b](3)progress.php[/b]
<?php
$id = md5(uniqid(rand(), true));
?>
<html>
<head><title>php文件上传进度</title></head>
<body>
<script type="text/javascript">
var xmlHttp;
var proNum=0;
var loop=0;
var Try = {
these: function() {
var returnValue;
for (var i = 0; i < arguments.length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
}
catch (e) {}
}
return returnValue;
}
}
function createXHR(){
return Try.these(
function() {return new XMLHttpRequest()},
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
) || false;
}
var xmlHttp;
function sendURL() {
xmlHttp=createXHR();
var url="getprogress.php?progress_key=<?php echo $id;?>";
xmlHttp.onreadystatechange=doHttpReadyStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function doHttpReadyStateChange() {
if (xmlHttp.readyState == 4){
proNum=parseInt(xmlHttp.responseText);
document.getElementById("progressinner").style.width = proNum+"%";
document.getElementById("showNum").innerHTML = proNum+"%";
if (proNum<100){
setTimeout("getProgress()",500);
}
else
{
window.theframe.location.href='upload.php?add=ok';
}
}
}
function getProgress(){
loop++;
document.getElementById("showNum2").innerHTML = loop;
sendURL();
}
function startProgress(){
document.getElementById("progressouter").style.display="block";
setTimeout("getProgress()",500);
window.theframe.upload_form.submit();
}
</script>
<iframe id="theframe" name="theframe" src="upload.php?id=<?php echo($id); ?>" style=" height:20px; width: 190px;" frameborder="0" scrolling="no">
</iframe>
<div id="progressouter" style="font-size:0px;width:300px;height:5px;border: 1px solid red;display:none;">
<div id="progressinner" style="font-size:0px;position: relative; height:5px; background-color: purple; width:0%;">
</div>
</div><div id='showNum'></div><br>
<div id='showNum2'></div>
</body>
</html>
[b](4)target.php[/b]
<?php
set_time_limit(600);
if($_SERVER['REQUEST_METHOD']=='POST') {
move_uploaded_file($_FILES["test_file"]["tmp_name"],dirname($_SERVER['SCRIPT_FILENAME'])."/upload/" . $_FILES["test_file"]["name"]);//UploadTemp文件夹位于此脚本相同目录下
}
?>
[b]3.打开progress.php进行测试,可以把源码修改成更好的![/b]