使用PECL模塊安裝方法安裝該模塊
PHP.ini裡面設置 uploadprogress.file.filename_template = “/tmp/upd_%s.txt”
代碼范例:
if($_SERVER['REQUEST_METHOD']=='POST') {
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
$upload_dir = 'your_path/';
$ext = strrchr($_FILES['video']['name'], '.');
$sessid = $_POST['UPLOAD_IDENTIFIER'] ;
$tmpfile = $upload_dir . $sessid;
$sessfile = $upload_dir . $sessid .$ext;
if (move_uploaded_file($_FILES['upfile']['tmp_name'],$tmpfile)) {
//上傳成功
} else {
//上傳失敗
} else {
//上傳錯誤
} elseif (!empty($_GET['sessid'])) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-ModifIEd: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Type:text/Html;charset=UTF-8");
$unique_id = $_GET['sessid'];
$uploadvalues = uploadprogress_get_info($unique_id);
if (is_array($uploadvalues)) {
echo JSon_encode($uploadvalues);
} else {
//讀取進度失敗,另外處理邏輯
}
} else {
//顯示上傳表單
}