PHP檔案上傳帶進度條(1/3)_PHP教程

來源:互聯網
上載者:User
實現篇
一般情況,用php教程實現上傳進度條就下面兩種方法:
1.apc擴充(作者是php教程的創始人,5.2後php已經加入apc擴充)
2.pecl擴充模組 uploadprogress
不論是apc還是uploadprogress,都需要編譯源碼教程,因為原有的php函數根本不可能讀取到臨時檔案夾裡的東西。下面來看如何使用以及關鍵的代碼:apc實現方法:
1.安裝apc
2.配置php.ini,設定參數 apc.rfc1867=1
3.關鍵代碼:

if ($_server['request_method'] == ‘post’) { //上傳請求
$status = apc_fetch(’upload_’ . $_post['apc_upload_progress']);
$status['done'] = 1;
echo json_encode($status); //輸出給使用者端頁面裡的ajax調用,相關文檔請自己尋找
exit;
} elseif (isset($_get['progress_key'])) { //讀取上傳進度
$status = apc_fetch(’upload_’.$_get['progress_key']);
echo json_encode($status);
exit;
}

uploadprogress實現方法:
1.使用pecl 安裝uploadprogress
2.php.ini裡面設定 uploadprogress.file.filename_template = “/tmp/upd_%s.txt”
3.關鍵代碼:

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)) {
//上傳成功
}
}

1 2 3

http://www.bkjia.com/PHPjc/444914.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444914.htmlTechArticle實現篇 一般情況,用php教程實現上傳進度條就下面兩種方法: 1.apc擴充(作者是php教程的創始人,5.2後php已經加入apc擴充) 2.pecl擴充模組...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.