ajax|上傳
代碼分為以下部分:
demo.php - 上傳過程處理
PLAIN TEXTPHP:
<?php
include 'UploadProgressMeter.class.php';
$fileWidget = new UploadProgressMeter();
if ($fileWidget->uploadComplete()) {
// 上傳完畢的時候,從iframe發送一個js到主視窗表示一切ok
echo $fileWidget->finalStatus();
// 處理上傳後的檔案...
exit;
}
?>
demoserver.php - ajax的服務端js,使用Pear:HTML_AJAX,直接調用UploadProgressMeterStatus類
PLAIN TEXTHTML:
<script src="http://www.ooso.net/demoserver.php?client=main,request,httpclient,dispatcher,json,util" type="text/javascript"></script>
<script src="http://www.ooso.net/demoserver.php?stub=UploadProgressMeterStatus" type="text/javascript"></script>
<?php echo $fileWidget->renderIncludeJs(); ?>
進度條的樣式表
PLAIN TEXTCSS:
.progressBar {
position: relative;
padding: 2px;
width: 300px;
height: 40px;
font-size: 14px;
}
.progressBar .background {
border: solid 1px black;
width: 270px;
height: 20px;
}
.progressBar .bar {
position: relative;
background-color: blue;
width: 0px;
height: 20px;
}
表單部分
PLAIN TEXTHTML:
<form action="demo.php" method="post" enctype="multipart/form-data">renderFormExtra(); ?>>
<?php echo $fileWidget->renderHidden(); ?></form><form action="demo.php" method="post" enctype="multipart/form-data"><label>Select File: </label>
<div><?php echo $fileWidget->render(); ?>
<?php echo $fileWidget->renderProgressBar(); ?></div>
</form>
demo下載 - 密碼是www.ooso.net
作者的svn瀏覽
其它類似項目:
http://pdoru.from.ro/ - 要以patch的形式和php一起編譯
http://www.ugia.cn/?p=54 - 以socket上傳檔案並顯示進度條