国产综合精品在线,精品一区国产精品,中文在线欧美日韩视频,中文字幕制服亚洲另类

<dfn id="ykamo"><pre id="ykamo"></pre></dfn>
  • <rt id="ykamo"><code id="ykamo"></code></rt>
  • <strike id="ykamo"></strike>
    php ajax實(shí)現(xiàn)文件上傳進(jìn)度條
    來(lái)源:易賢網(wǎng) 閱讀:1269 次 日期:2016-08-31 15:03:10
    溫馨提示:易賢網(wǎng)小編為您整理了“php ajax實(shí)現(xiàn)文件上傳進(jìn)度條”,方便廣大網(wǎng)友查閱!

    本實(shí)例是關(guān)于php文件上傳時(shí)進(jìn)度條的實(shí)現(xiàn),主要采用ajax技術(shù),另外還運(yùn)用了html5,有需要的朋友可以研究一下。

    本實(shí)例有兩個(gè)文件:

    upload_form.html:

    <!DOCTYPE html>

    <html>

    <head>

    <script>

    function _(el){

      return document.getElementById(el);

    }

    function uploadFile(){

      var file = _("file1").files[0];

      // alert(file.name+" | "+file.size+" | "+file.type);

      var formdata = new FormData();

      formdata.append("file1", file);

      var ajax = new XMLHttpRequest();

      ajax.upload.addEventListener("progress", progressHandler, false);

      ajax.addEventListener("load", completeHandler, false);

      ajax.addEventListener("error", errorHandler, false);

      ajax.addEventListener("abort", abortHandler, false);

      ajax.open("POST", "file_upload_parser.php");

      ajax.send(formdata);

    }

    function progressHandler(event){

      _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;

      var percent = (event.loaded / event.total) * 100;

      _("progressBar").value = Math.round(percent);

      _("status").innerHTML = Math.round(percent)+"% uploaded... please wait";

    }

    function completeHandler(event){

      _("status").innerHTML = event.target.responseText;

      _("progressBar").value = 0;

    }

    function errorHandler(event){

      _("status").innerHTML = "Upload Failed";

    }

    function abortHandler(event){

      _("status").innerHTML = "Upload Aborted";

    }

    </script>

    </head>

    <body>

    <h2>HTML5 File Upload Progress Bar Tutorial</h2>

    <form id="upload_form" enctype="multipart/form-data" method="post">

     <input type="file" name="file1" id="file1"><br>

     <input type="button" value="Upload File" onclick="uploadFile()">

     <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>

     <h3 id="status"></h3>

     <p id="loaded_n_total"></p>

    </form>

    </body>

    </html>

    file_upload_parser.php:

    <?php

    $fileName = $_FILES["file1"]["name"]; // The file name

    $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder

    $fileType = $_FILES["file1"]["type"]; // The type of file it is

    $fileSize = $_FILES["file1"]["size"]; // File size in bytes

    $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true

    if (!$fileTmpLoc) { // if file not chosen

      echo "ERROR: Please browse for a file before clicking the upload button.";

      exit();

    }

    if(move_uploaded_file($fileTmpLoc, "test_uploads/$fileName")){

      echo "$fileName upload is complete";

    } else {

      echo "move_uploaded_file function failed";

    }

    ?>

    以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:php ajax實(shí)現(xiàn)文件上傳進(jìn)度條
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)