Jquery上傳插件 uploadify v3.1使用說明
更新時間:2012年06月18日 14:27:09 作者:
uploadify ,簡單實用的flash上傳組件,兼容性良好。 現(xiàn)已有html5版本
官方地址:http://www.uploadify.com/
腳本之家提供的下載地址:http://www.dhdzp.com/jiaoben/21484.html
官方英文文檔:http://www.uploadify.com/documentation/
使用方法(.net版本):
前臺JS
$("#id").uploadify({
height: 30,
swf: '/uploadify/uploadify.swf',
uploader: '/Handler/uploadPic.ashx',
width: 120,
cancelImg: '/uploadify/uploadify-cancel.png',
buttonText: '選擇圖片',
fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png',
'fileSizeLimit': '6000KB',
removeCompleted: false,
'formData': {
"id":"1"
},
onUploadSuccess: function (file, data, response) {//上傳完成時觸發(fā)(每個文件觸發(fā)一次)
if (data.indexOf('錯誤提示') > -1) {
alert(data);
}
else {
//$("#previewImage").attr("src", data.substr(2)).hide().fadeIn(2000);
alert("上傳成功!");
}
},
'onUploadError': function (file, errorCode, errorMsg, errorString) {//當(dāng)單個文件上傳出錯時觸發(fā)
alert('文件:' + file.name + ' 上傳失敗: ' + errorString);
} });
ASHX文件:
protected string AllowExt = "7z|aiff|asf|avi|bmp|csv|doc|docx|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pptx|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xlsx|xml|zip";//支持的文件格式
int FileMaxSize = 10240;//文件大小,單位為Kpublicvoid ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string ParentID = context.Request.Params["id"];
HttpPostedFile fileUpload = context.Request.Files[0];
if (fileUpload != null)
{
try
{
string UploadDir = "~/upload/";//圖片保存的文件夾
//圖片保存的文件夾路徑
string path = context.Server.MapPath(UploadDir);
//每天上傳的圖片一個文件夾
string folder = DateTime.Now.ToString("yyyyMM");
//如果文件夾不存在,則創(chuàng)建
if (!Directory.Exists(path + folder))
{
Directory.CreateDirectory(path + folder);
}
//上傳圖片的擴展名
string fileExtension = fileUpload.FileName.Substring(fileUpload.FileName.LastIndexOf('.'));
//判斷文件格式
if (!CheckValidExt(fileExtension))
{
context.Response.Write("錯誤提示:文件格式不正確!" + fileExtension);
return;
}
//判斷文件大小
if (fileUpload.ContentLength > FileMaxSize * 1024)
{
context.Response.Write("錯誤提示:上傳的文件(" + fileUpload.FileName + ")超過最大限制:" + FileMaxSize + "KB");
return;
}
//保存圖片的文件名
//string saveName = Guid.NewGuid().ToString() + fileExtension;
//使用時間+隨機數(shù)重命名文件
string strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff");//取得時間字符串
Random ran = new Random();
string strRan = Convert.ToString(ran.Next(100, 999));//生成三位隨機數(shù)
string saveName = strDateTime + strRan + fileExtension;
Model.Album uc = new Model.Album();
uc.Title = fileUpload.FileName;
uc.ImagePath = folder + "/" + saveName;
uc.PostTime = DateTime.Now;
uc.Pid= int.Parse(id);
bll.Album alb = new bll.Album();
alb.add(uc);
//保存圖片
fileUpload.SaveAs(path + folder + "/" + saveName);
context.Response.Write(UploadDir + folder + "/" + saveName);
}
catch
{
context.Response.Write("錯誤提示:上傳失敗");
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
#region 檢測擴展名的有效性 bool CheckValidExt(string sExt)
/// <summary>
/// 檢測擴展名的有效性
/// </summary>
/// <param name="sExt">文件名擴展名</param>
/// <returns>如果擴展名有效,返回true,否則返回false.</returns>
public bool CheckValidExt(string strExt)
{
bool flag = false;
string[] arrExt = AllowExt.Split('|');
foreach (string filetype in arrExt)
{
if (filetype.ToLower() == strExt.ToLower().Replace(".", ""))
{
flag = true;
break;
}
}
return flag;
}
#endregion
參數(shù)說明:
參考 http://www.dhdzp.com/article/30598.htm
3.1 版本更新 : 去除postData,更改為formData。 Json數(shù)據(jù)。 其他更改研究中。
上傳文件生成縮略圖顯示到網(wǎng)頁功能研究ing。
腳本之家提供的下載地址:http://www.dhdzp.com/jiaoben/21484.html
官方英文文檔:http://www.uploadify.com/documentation/
使用方法(.net版本):
前臺JS
復(fù)制代碼 代碼如下:
$("#id").uploadify({
height: 30,
swf: '/uploadify/uploadify.swf',
uploader: '/Handler/uploadPic.ashx',
width: 120,
cancelImg: '/uploadify/uploadify-cancel.png',
buttonText: '選擇圖片',
fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png',
'fileSizeLimit': '6000KB',
removeCompleted: false,
'formData': {
"id":"1"
},
onUploadSuccess: function (file, data, response) {//上傳完成時觸發(fā)(每個文件觸發(fā)一次)
if (data.indexOf('錯誤提示') > -1) {
alert(data);
}
else {
//$("#previewImage").attr("src", data.substr(2)).hide().fadeIn(2000);
alert("上傳成功!");
}
},
'onUploadError': function (file, errorCode, errorMsg, errorString) {//當(dāng)單個文件上傳出錯時觸發(fā)
alert('文件:' + file.name + ' 上傳失敗: ' + errorString);
} });
ASHX文件:
復(fù)制代碼 代碼如下:
protected string AllowExt = "7z|aiff|asf|avi|bmp|csv|doc|docx|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pptx|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xlsx|xml|zip";//支持的文件格式
int FileMaxSize = 10240;//文件大小,單位為Kpublicvoid ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string ParentID = context.Request.Params["id"];
HttpPostedFile fileUpload = context.Request.Files[0];
if (fileUpload != null)
{
try
{
string UploadDir = "~/upload/";//圖片保存的文件夾
//圖片保存的文件夾路徑
string path = context.Server.MapPath(UploadDir);
//每天上傳的圖片一個文件夾
string folder = DateTime.Now.ToString("yyyyMM");
//如果文件夾不存在,則創(chuàng)建
if (!Directory.Exists(path + folder))
{
Directory.CreateDirectory(path + folder);
}
//上傳圖片的擴展名
string fileExtension = fileUpload.FileName.Substring(fileUpload.FileName.LastIndexOf('.'));
//判斷文件格式
if (!CheckValidExt(fileExtension))
{
context.Response.Write("錯誤提示:文件格式不正確!" + fileExtension);
return;
}
//判斷文件大小
if (fileUpload.ContentLength > FileMaxSize * 1024)
{
context.Response.Write("錯誤提示:上傳的文件(" + fileUpload.FileName + ")超過最大限制:" + FileMaxSize + "KB");
return;
}
//保存圖片的文件名
//string saveName = Guid.NewGuid().ToString() + fileExtension;
//使用時間+隨機數(shù)重命名文件
string strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff");//取得時間字符串
Random ran = new Random();
string strRan = Convert.ToString(ran.Next(100, 999));//生成三位隨機數(shù)
string saveName = strDateTime + strRan + fileExtension;
Model.Album uc = new Model.Album();
uc.Title = fileUpload.FileName;
uc.ImagePath = folder + "/" + saveName;
uc.PostTime = DateTime.Now;
uc.Pid= int.Parse(id);
bll.Album alb = new bll.Album();
alb.add(uc);
//保存圖片
fileUpload.SaveAs(path + folder + "/" + saveName);
context.Response.Write(UploadDir + folder + "/" + saveName);
}
catch
{
context.Response.Write("錯誤提示:上傳失敗");
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
#region 檢測擴展名的有效性 bool CheckValidExt(string sExt)
/// <summary>
/// 檢測擴展名的有效性
/// </summary>
/// <param name="sExt">文件名擴展名</param>
/// <returns>如果擴展名有效,返回true,否則返回false.</returns>
public bool CheckValidExt(string strExt)
{
bool flag = false;
string[] arrExt = AllowExt.Split('|');
foreach (string filetype in arrExt)
{
if (filetype.ToLower() == strExt.ToLower().Replace(".", ""))
{
flag = true;
break;
}
}
return flag;
}
#endregion
參數(shù)說明:
參考 http://www.dhdzp.com/article/30598.htm
3.1 版本更新 : 去除postData,更改為formData。 Json數(shù)據(jù)。 其他更改研究中。
上傳文件生成縮略圖顯示到網(wǎng)頁功能研究ing。
相關(guān)文章
jQuery實現(xiàn)的上傳圖片本地預(yù)覽效果簡單示例
這篇文章主要介紹了jQuery實現(xiàn)的上傳圖片本地預(yù)覽效果,結(jié)合實例形式分析了jQuery上傳圖片本地預(yù)覽所涉及的相關(guān)頁面元素屬性動態(tài)操作實現(xiàn)技巧,需要的朋友可以參考下2018-03-03
jquery輸入數(shù)字隨機抽獎特效的簡單實現(xiàn)代碼
下面小編就為大家?guī)硪黄猨query輸入數(shù)字隨機抽獎特效的簡單實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06
使用jQuery在移動頁面上添加按鈕和給按鈕添加圖標(biāo)
這篇文章主要介紹了使用jQuery在移動頁面上增加按鈕和給按鈕添加圖標(biāo)的方法,用到了針對移動開發(fā)的jQuery mobile庫,需要的朋友可以參考下2015-12-12
基于jquery ui的alert,confirm方案(支持換膚)
這篇文章主要介紹了基于jquery ui的alert,confirm方案(支持換膚),修改自網(wǎng)友的源碼,有需要的小伙伴參考下。2015-04-04
jQuery插件HighCharts實現(xiàn)的2D條狀圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts實現(xiàn)的2D條狀圖效果,結(jié)合完整實例形式詳細分析了jQuery插件HighCharts繪制2D條狀圖的操作步驟與相關(guān)屬性設(shè)置技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03
jQuery簡單實現(xiàn)對數(shù)組去重及排序操作實例
這篇文章主要介紹了jQuery簡單實現(xiàn)對數(shù)組去重及排序操作,結(jié)合實例形式分析了jQuery中unique方法進行數(shù)組去重及sort方法排序的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
使用JS或jQuery模擬鼠標(biāo)點擊a標(biāo)簽事件代碼
這篇文章主要介紹了使用JS或jQuery模擬鼠標(biāo)點擊a標(biāo)簽事件代碼,需要的朋友可以參考下2014-03-03
jquery插件pagination實現(xiàn)無刷新ajax分頁
這篇文章主要介紹了jquery插件pagination實現(xiàn)無刷新ajax分頁的相關(guān)資料,需要的朋友可以參考下2015-09-09
Jquery 過濾器(first,last,not,even,odd)的使用
Jquery 過濾器,顧名思義就是過濾一些不需要的元素,主要有first,last,not,even,odd等等,下面有個使用示例,大家可以感受下2014-01-01

