国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

文件上傳~Uploadify上傳控件

2019-11-17 01:27:45
字體:
來源:轉載
供稿:網友

文件上傳~Uploadify上傳控件

對于文件上傳來說,有很多種實現方式,如傳統的表單方式,現在流行的Flash方式,甚至還有純JS方式,之所以有這些方式來實現文件上傳,我想主要原因是因為,傳統的上傳對于大文件支持不夠,因為它是單線程同步機制,當大文件通過HTTP方式發送到服務端時,對于服務端站點的主線程影響比較大,會產生阻塞,所以,現在很多上傳控制都是異步,多線程的方式去實現的.

今天來介紹一個文件上傳控制,它就是Uploadify,它應該是flash的異步上傳工具,對于大文件支持還不錯,所以,我選擇了它.

相關API介紹

uploader : uploadify.swf 文件的相對路徑,該swf文件是一個帶有文字BROWSE的按鈕,點擊后淡出打開文件對話框,默認值:uploadify.swf。 script : 后臺處理程序的相對路徑 。默認值:uploadify.php checkScript :用來判斷上傳選擇的文件在服務器是否存在的后臺處理程序的相對路徑 fileDataName :設置一個名字,在服務器處理程序中根據該名字來取上傳文件的數據。默認為Filedata method : 提交方式Post 或Get 默認為Post scriptaccessflash腳本文件的訪問模式,如果在本地測試設置為always,默認值:sameDomain folder : 上傳文件存放的目錄 。 queueID : 文件隊列的ID,該ID與存放文件隊列的div的ID一致。 queueSizeLimit : 當允許多文件生成時,設置選擇文件的個數,默認值:999 。 multi : 設置為true時可以上傳多個文件。 auto : 設置為true當選擇文件后就直接上傳了,為false需要點擊上傳按鈕才上傳 。

fileExt : 設置可以選擇的文件的類型,格式如:'*.jpg;*.gif,*.png' 。

fileDesc : 這個屬性值必須設置fileExt屬性后才有效,用來設置選擇文件對話框中的提示文本,如設置fileDesc為“請選擇圖像文件”,sizeLimit : 上傳文件的大小限制 。 simUploadLimit : 允許同時上傳的個數 默認值:1 。 buttonText : 瀏覽按鈕的文本,默認值:BROWSE 。 buttonImg : 瀏覽按鈕的圖片的路徑 。 hideButton : 設置為true則隱藏瀏覽按鈕的圖片 。 rollover : 值為true和false,設置為true時當鼠標移到瀏覽按鈕上時有反轉效果。 width : 設置瀏覽按鈕的寬度 ,默認值:110。 height : 設置瀏覽按鈕的高度 ,默認值:30。 wmode : 設置該項為transparent 可以使瀏覽按鈕的flash背景文件透明,并且flash文件會被置為頁面的最高層。 默認值:opaque 。 cancelImg :選擇文件到文件隊列中后的每一個文件上的關閉按鈕圖標

結構圖

HTML代碼

<div>%20%20%20%20<div%20class="inputDiv%20fl">%20%20%20%20%20%20%20%20<input%20type="text"%20name="ImagePath"%20id="ImagePath"%20style="width:%20600px;">%20%20%20%20%20%20%20%20<img%20style="display:%20none;"%20/>%20%20%20%20</div>%20%20%20%20<div%20class="fl"%20style="position:%20relative;">%20%20%20%20%20%20%20%20<input%20id="custom_file_uploadEdu"%20type="file"%20class="btn"%20/>%20%20%20%20%20%20%20%20<a%20href="javascript:$('#custom_file_uploadEdu').uploadifyUpload()">上傳</a>|%20%20%20%20%20%20%20<a%20href="Javascript:$('#custom_file_uploadEdu').uploadifyClearQueue()">取消上傳</a>%20%20%20%20</div>%20%20%20%20<div%20id="displayMsg"></div></div>

JS代碼

<script%20type="text/ecmascript">%20%20%20%20$("#custom_file_uploadEdu").uploadify({%20%20%20%20%20%20%20%20'uploader':%20'/Scripts/Uploadify/uploadify.swf',%20%20%20%20%20%20%20%20'script':%20'/ashx/UploadFile.ashx',%20%20%20%20%20%20%20%20'cancelImg':%20'/Scripts/Uploadify/uploadify-cancel.png',        'folder': '/',        'queueSizeLimit': 1,        'simUploadLimit': 1,        'sizeLimit ': 1024 * 1024 * 5,        'multi': false,        'auto': false,/*如果是自動上傳,那上傳按鈕將沒用了*/        'fileExt': '*.jpg;*.gif;*.jpeg;*.mp4',        'fileDesc': '請選擇圖像或者視頻',        'queueID': 'fileQueue',        'width': 110,        'height': 30,        'buttonText': '選擇',        'wmode': 'opaque',        'hideButton': false,        'onSelect': function (event, ID, fileObj) {            $("#displayMsg").html("上傳中......");        },        'onComplete': function (event, queueId, fileObj, response, data) {            var ary = response.split('|');            if (ary[0] == "0") { //提示錯誤信息                alert(ary[1]);            }            else {                if (ary[0]=="1") {//上傳后的URL                    $("#displayMsg").html("上傳成功")                    $("#ImagePath").attr("value", ary[1]);                    $("#ImagePath").remove("img").next("img").show().attr({ "style": "width:50px;height:50px;", "src": ary[1] });                } else {//異常信息                    alert(ary[1]);                }            }        }    });</script>

后臺處理程序(接收流,寫入流)

namespace WebTest.ashx{    /// <summary>    /// UploadFile 的摘要說明    /// </summary>    public class UploadFile : IHttpHandler    {        public void PRocessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            context.Response.Write(new UploadImpl().Upload(context, UpLoadType.ProductImage, false));        }        public bool IsReusable        {            get            {                return false;            }        }    }}

UploadImpl類代碼

namespace EntityFrameworks.application.Core.FileUpload{    /// <summary>    /// 圖像上傳功能的實現    /// </summary>    public class UploadImpl    {        public UploadImpl(IFileUploadSize fileUploadSize)        {            _fileUploadSize = fileUploadSize ?? new TestFileUploadSize();        }        public UploadImpl()            : this(null)        {        }        #region Fields & Consts        static string FileHostUri = System.Configuration.ConfigurationManager.AppSettings["FileHostUri"]            ?? HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority;        Point point = new Point(0, 0); //圖像從那個坐標點進行截取        double wRate = 1, hRate = 1, setRate = 1;        int newWidth = 0, newHeight = 0;        IFileUploadSize _fileUploadSize;        #endregion        #region  圖像縮放        /// <summary>        /// 圖像的縮放        /// </summary>        /// <param name="file">縮放文件</param>        /// <param name="width">寬</param>        /// <param name="height">高</param>        /// <param name="isEqualScale">是否等比例縮放</param>        /// <param name="name">縮放后存放的地址</param>        /// <returns></returns>        bool CreateThumbnail(HttpPostedFile file, ImageSize imageSize, bool isEqualScale, string name)        {            double width = (double)imageSize.Width;            double height = (double)imageSize.Height; ;            try            {                System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream);                if (isEqualScale)                {                    if (image.Height > height)                    {                        hRate = height / image.Height;                    }                    if (image.Width > width)                    {                        wRate = width / image.Width;                    }                    if (wRate != 1 || hRate != 1)                    {                        if (wRate > hRate)                        {                            setRate = hRate;                        }                        else                        {                            setRate = wRate;                        }                    }                    newWidth = (int)(image.Width * setRate);                    newHeight = (int)(image.Height * setRate);                    if (height > newHeight)                    {                        point.Y = Convert.ToInt32(height / 2 - newHeight / 2);                    }                    if (width > newWidth)                    {                        point.X = Convert.ToInt32(width / 2 - newWidth / 2);                    }                }                Bitmap bit = new Bitmap((int)(width), (int)(height));                Rectangle r = new Rectangle(point.X, point.Y, (int)(image.Width * setRate), (int)(image.Height * setRate));                Graphics g = Graphics.FromImage(bit);                g.Clear(Color.White);                g.DrawImage(image, r);                MemoryStream ms = new MemoryStream();                bit.Save(ms, ImageFormat.Jpeg);                byte[] bytes = ms.ToArray();                string fileName = name + imageSize.ToString();//為縮放圖像重新命名                using (FileStream stream = new FileStream(fileName, Fil
上一篇:agsxmpp

下一篇:ASP.NET Eval四種綁定方式

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庄河市| 如皋市| 肥东县| 绍兴县| 集安市| 承德市| 平度市| 龙山县| 定兴县| 黔东| 陵水| 长春市| 萍乡市| 荔浦县| 商洛市| 武鸣县| 奇台县| 夹江县| 翁牛特旗| 芜湖市| 沙坪坝区| 文安县| 金华市| 万年县| 明光市| 四平市| 嵊州市| 正阳县| 扶风县| 鄯善县| 仁寿县| 龙井市| 武义县| 玛纳斯县| 六盘水市| 遂昌县| 武夷山市| 莒南县| 扎囊县| 攀枝花市| 克东县|