0
我想用PECL uploadprogress擴展實現一個非常基本的AJAX上傳進度條。我發現這個示例代碼適用於所有瀏覽器:http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/。它使用iframe將更新寫入。我想獲得更新,並做一些jQuery來建立一個進度條。這裏是我的代碼(我知道我沒有寫代碼,考慮到當上載結束)client.php:PECL Uploadprogress不會給我上傳進度
<?php
$id = md5(microtime() . rand());
?>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function getProgress(){
$.get("progress.php", {"ID":'<?php echo $id ?>'}, function(data){
console.log(data);
});
window.setTimeout(getProgress(), 5000);
}
</script>
<body>
<form onsubmit="getProgress()" target="_self" enctype="multipart/form-data" method="post">
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $id;?>" />
<label>Select File:</label>
<input type="file" name="file" />
<br/>
<label>Select File:</label>
<input type="file" name="file2" />
<br/>
<label>Upload File:</label>
<input id="submitButton" type="submit" value="Upload File" />
</form>
</body>
</html>
而且progress.php:
<?php
if (function_exists("uploadprogress_get_info")) {
$info = uploadprogress_get_info($_GET['ID']);
} else {
$info = false;
}
$progress = ($info['bytes_uploaded']/$info['bytes_total'])*100;
echo $progress;
我出錯誤和所有打印是0的。有任何想法嗎?
PHP是以Apache模塊還是cgi運行? PECL上傳進度將只適用於mod_php。 – c2h5oh
我已確認使用iframe的演示代碼確實有效。我正在努力將其削減到最基本的要求。 – Julian