久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

向老式文件上傳添加不顯眼的進度條

Adding unobtrusive progress bar to old-school file uploads(向老式文件上傳添加不顯眼的進度條)
本文介紹了向老式文件上傳添加不顯眼的進度條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

你們都知道新一代花哨的,主要是基于 Flash 的文件上傳器,例如 SWFUpload 可以在上傳時顯示進度條 - 一個很大的改進,特別是對于不穩定和低帶寬的連接.

You all know the new generation of fancy, mostly Flash-based file uploaders like SWFUpload that can show a progress bar while uploading - a great improvement especially for shaky and low-bandwidth connections.

然而,這些上傳者都自帶了如何在客戶端處理上傳的邏輯.我正在尋找一種不顯眼的方式來幻想"現有的經典文件上傳,即在普通文件上傳表單中引入進度條.

However, these uploaders all bring their own logic of how to handle uploads on the client side. I am looking for an unobtrusive way to "fancify" existing, classical file uploads, i.e. introducing a progress bar to normal file upload forms.

由于上傳文件的架構,如果不在客戶端進行一些調整,這很可能是不可能的.

Due to the architecture of uploading files, this is most likely not possible without some tweaking on the client side.

我正在尋找一種將調整保持在絕對最小值的解決方案,例如一個將自身添加到普通表單的 onsubmit 事件的組件,執行文件上傳,顯示一個漂亮的進度條,將生成的臨時(服務器端)文件路徑放入表單中,然后提交.在服務器端,我只需要修改我的腳本以使用flash上??傳器提供的文件路徑,而不是$_FILES和consorts,并考慮一下安全性.

I am looking for a solution that keeps the tweaking to an absolute minimum, e.g. a component that adds itself to the onsubmit event of a normal form, performs the file upload, displays a nice progress bar, puts the resulting temporary (server side) file path into the form, and submits it. On the server side, I just have to modify my script to use the file path provided by the flash uploader, instead of $_FILES and consorts, and think about security for a moment.

這并不是所有基于 Flash 的上傳者所做的:他們可以使用表單中的數據,但他們不提供按原樣提交表單的可能性,我正在尋找什么.我正在尋找更進一步的(可能)基于 Flash 的上傳功能.

推薦答案

我們通過安裝 PECL 擴展pecl-uploadprogress 并在表單中添加了一個簡單的 AJAX 回調來實現這一點:

We implemented this very simple by installing the PECL extension pecl-uploadprogress and added a simple AJAX callback to the forms:

生成上傳密鑰:

$upload_id = genUploadKey();
function genUploadKey ($length = 11) {
  $charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  for ($i=0; $i < $length; $i++)
    $key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
  return $key;
}

創建一個 AJAX 回調處理程序(例如 uploadprogress.php):

Create an AJAX callback handler (eg. uploadprogress.php):

extract($_REQUEST);

// servlet that handles uploadprogress requests:
if ($upload_id) {
  $data = uploadprogress_get_info($upload_id);
  if (!$data)
    $data['error'] = 'upload id not found';
  else {
    $avg_kb = $data['speed_average'] / 1024;
    if ($avg_kb<100)
      $avg_kb = round($avg_kb,1);
    else if ($avg_kb<10)
      $avg_kb = round($avg_kb,2);
    else $avg_kb = round($avg_kb);

    // two custom server calculations added to return data object:
    $data['kb_average'] = $avg_kb;
    $data['kb_uploaded'] = round($data['bytes_uploaded'] /1024);
  }

  echo json_encode($data);
  exit;
}

// display on completion of upload:
if ($UPLOAD_IDENTIFIER) {
...

下載 jQuery 和 jQuery.uploadprogress 庫(其中還包括上述代碼段)并與您的表單集成:

Download jQuery and the jQuery.uploadprogress libraries (which also includes the above snippet) and integrate with your form:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.uploadprogress.0.3.js"></script>
<script type="text/javascript">
jQuery(function () {
    // apply uploadProgress plugin to form element
    // with debug mode and array of data fields to publish to readout:
    jQuery('#upload_form').uploadProgress({
        progressURL:'uploadprogress.php',
        displayFields : ['kb_uploaded','kb_average','est_sec'],
        start: function() {
            $('.upload-progress').show();
        },
    success: function() {
            $('.upload-progress').hide();
            jQuery(this).get(0).reset();
        }
    });
});
</script>

將此添加到您的上傳表單:

Add this to your upload form:

<input name="UPLOAD_IDENTIFIER" type="hidden" value="$upload_id" />

這應該可以解決問題.這是從我們的代碼庫中提取的,可能無法開箱即用.但它應該告訴你這個想法.

That should do the trick. This is extracted from our code base and may not work out-of-the-box. But it should tell you the idea.

這篇關于向老式文件上傳添加不顯眼的進度條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 综合久久亚洲 | 国产黄色麻豆视频 | 国产精品免费一区二区三区四区 | 欧美日韩国产一区二区 | 久久99视频 | 日本久久久久久久久 | 黄色三级免费 | 一区二区三区四区视频 | 国产精品69久久久久水密桃 | 欧美精品一区二区三区四区五区 | 欧美精品综合在线 | 国产精品美女 | 久久久免费 | 亚洲精品中文字幕av | 99精品国产成人一区二区 | 成人精品鲁一区一区二区 | 国产亚洲精品精品国产亚洲综合 | 国产1区 | 久久久精品视频免费看 | 国产99久久精品一区二区永久免费 | 国产亚洲一区二区三区在线 | 亚洲精品久久久久中文字幕欢迎你 | 亚洲精品视频在线 | 四虎影院在线播放 | 99久久婷婷国产综合精品首页 | 久久久91精品国产一区二区三区 | 精品中文字幕一区二区 | 欧美一级做性受免费大片免费 | 日韩三级在线观看 | 99国产精品99久久久久久 | 中文字幕日本一区二区 | 日韩在线中文字幕 | 天天综合久久 | 国产在线对白 | 日韩久久久久久 | 国产成人精品综合 | 在线观看亚洲 | 99久久久久久99国产精品免 | 中文字幕91 | 羞羞视频免费观 | 99亚洲精品 |