1. 程式人生 > >檔案上傳進度條顯示

檔案上傳進度條顯示

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
<style>
        body { padding: 30px }
        form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }


        .progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
        .bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
        .percent { position:absolute; display:inline-block; top:3px; left:48%; }
    </style>


</head>
<body>
<form id="myForm" action="/uploadLocalVideoAndInfo" method="post" enctype="multipart/form-data">
    <div class="col-md-2" style="line-height:25px;text-align:right;margin-right:20px;"><label for="upload-file-input">視訊名稱</label></div>                
    <input type="text" name="videoName" />
    <input type="file" name="uploadFile" /><br>
     <div class="col-md-2" style="line-height:25px;text-align:right;margin-right:20px;"><label for="upload-file-input">拍攝地點</label></div>                
     <input type="text" name="videoPlace"  />
    <input type="submit" value="Upload File to Server">
</form>


<div class="progress">
    <div class="bar"></div >
    <div class="percent">0%</div >
</div>


<div id="status"></div>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js" integrity="sha384-FzT3vTVGXqf7wRfy8k4BiyzvbNfeYjK+frTVqZeNDFl8woCbF0CYG6g2fMEFFo/i" crossorigin="anonymous"></script>




<!-- <script src="/static/js/jquery.form.js"></script> -->
<script>


    $(function(){
        var bar = $('.bar');
        var percent = $('.percent');
        var status = $('#status');
        $('#myForm').ajaxForm(
       
        
        {
            beforeSerialize:function(){
                //alert("表單資料序列化前執行的操作!");
                //$("#txt2").val("java");//如:改變元素的值
            },
            beforeSubmit:function(){
                //alert("表單提交前的操作");
                var filesize = $("input[type='file']")[0].files[0].size/1024/1024;
                if(filesize > 1000){
                    alert("檔案大小超過限制,最多1000M");
                    return false;
                }
                //if($("#txt1").val()==""){return false;}//如:驗證表單資料是否為空
            },
            beforeSend: function() {
                status.empty();
                var percentVal = '0%';
                bar.width(percentVal)
                percent.html(percentVal);
            },
            uploadProgress: function(event, position, total, percentComplete) {//上傳的過程
                //position 已上傳了多少
                //total 總大小
                //已上傳的百分數
                var percentVal = percentComplete + '%';
                bar.width(percentVal)
                percent.html(percentVal);
                //console.log(percentVal, position, total);
            },
            success: function(data) {//成功
                var percentVal = '100%';
                bar.width(percentVal)
                percent.html(percentVal);
                //alert(data);
            },
            error:function(err){//失敗
                alert("表單提交異常!"+err.msg);
            },
            complete: function(xhr) {//完成
                status.html(xhr.responseText);
            }
        });


    });


</script>
</body>
</html>

相關推薦

檔案進度顯示

<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Insert title here</title> <style>

ajax FormData檔案和資料,進度顯示

http://www.jb51.net/article/114003.htm 一、基於input 方式formData上傳檔案和資料: <divclass="startleft describebox"> <labelclass="title">商

servlet+jquery實現檔案進度

      現在檔案的上傳,特別是大檔案上傳,都需要進度條,讓客戶知道上傳進度。       本文簡單記錄下如何弄進度條,以及一些上傳資訊,比如檔案的大小,上傳速度,預計剩餘時間等一些相關資訊。程式碼是匆忙下簡單寫的,一些驗證沒做,或程式碼存在一些隱患,不嚴謹的地方。本文程

SpringMVC實現的檔案進度Bootstrap展示

背景 想做一個帶進度條的檔案上傳,可是搜尋的結果都不是很滿意,最後參考一個實踐了一下,基於SpringMVC實現,前端採用Bootstrap。 整理一下進度條的實現。 效果 先看最後的效果 實現步驟 前提 SpringMVC已經配置

javaweb實現檔案進度功能

一、建立幫助類package com.xxxx.xxxx.util;public class Progress {private long bytesRead;    private long contentLength;        private long items;

php+ajax檔案進度

demo.php - 上傳過程處理 PLAIN TEXTPHP: <?php include 'UploadProgressMeter.class.php'; fileWidget = new UploadProgressMeter(); if (fileWidget

Layui多檔案進度

Layui原生upload模組不支援檔案上傳進度條顯示,百度,谷歌找了一下不太適用。後面找到一個別人修改好的JS,替換上去,修改一下頁面顯示即可使用,一下是部分程式碼 HTML: <div class="layui-upload"> <button type="butto

cgi 檔案(c 語言) 進度顯示

//虛擬機器上搭建apache伺服器上傳檔案 //1.程式碼: #include "stdio.h" #include "string.h" #include "stdlib.h" #include "dirent.h" #include <wchar.h> #i

js 檔案下載/ 進度

/** * 下載檔案 - 帶進度監控 * @param url: 檔案請求路徑 * @param params: 請求引數 * @param name: 儲存的檔名 * @param progress: 進度處理回撥函式 * @param success: 下載完成回

檔案進度upload_progress

前端: <form id="upload-form" action="upload.php" method="POST" enctype="multipart/form-data">         <input type="hidden"

SpringBoot+fileUpload獲取檔案進度

我本人在網上找了很多關於檔案上傳進度獲取的文章,普遍基於spring MVC 框架通過 fileUpload 實現,對於spring Boot 通過 fileUpload 實現的帖子非常少,由於小弟學藝不精,雖然 Spring Boot 和 Spring MVC 相差不大,只是配置方式的

JS 檔案讀取的進度顯示方法(FileReader、onprogress)——20181116

這裡FileReader只是從磁碟把檔案讀取到瀏覽器,並沒有傳送到伺服器。參考連結1       參考連結2 <!DOCTYPE html> <html > <head> <meta charset="UTF-8"

input type=''file''美化 及 檔案img src顯示問題

                                                                                         原始介面        

OkHttp實現檔案進度

檔案上傳就一個沒刻度的進度條在那裡轉怎麼行,本篇帶你實現上傳進度,為你的進度條新增刻度吧,啥都不說了,重點重寫RequestBody,看程式碼 import com.squareup.okhttp.*; import okio.Buffer; import

H5移動端多圖+進度

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width

thinkphp 檔案為什麼總是顯示沒有檔案解決方案

這個問題我百度了許久終於在一個博友那兒看到了解決方案,現在分享給大家! 使用ThinkPhp框架上傳小圖片檔案成功,上傳大檔案失敗。  後來查找了原因,是因為php限制了上傳檔案的大小,修改php.ini如下配置: upload_max_filesize = 300M p

python實現檔案下載(包含進度顯示檔案大小顯示,下載速度顯示)

不多說了,直接上程式碼記錄: #!/usr/bin/lgy #-*-coding:utf-8-*- import urllib2,threading from PyQt4.QtGui import * from PyQt4.QtCore import * from pu

AJAX實現進度(Django)

昨天研究了一天檔案上傳進度條的實現,折騰了一天終於是完成了,期間遇到了各種BUG,讓人不禁淚落。 這裡,我們將使用最少量的AJAX來實現這個功能,沒有任何對瀏覽器支援性的檢測,這樣更容易明白。還有一點需要說明的是,後臺也是應該來摻和一腳(配合)的,當然,非常簡單,只要確認接

一鍵jquery非同步檔案(圖片)的實現(檔案進度讀取未做)

本文采用boostrap、、jquery、jade(html的一種模板)、nodejs實現 最終實現的效果:一個按鈕在選擇完檔案後,自動上傳到後臺; -改變input樣式 在form表單中,用<a>包裹<input type="file">,讓i

Web---檔案-用apache的工具處理、打散目錄、簡單檔案進度

我們需要先準備好2個apache的類: 上一個部落格文章只講了最簡單的入門,現在來開始慢慢加深。 先過渡一下:只上傳一個file項 index.jsp: <h2>用apache的工具處理檔案上傳</h2>