您的位置:首页 > 其它

Uploadify使用介绍

2011-06-30 16:50 155 查看
Uploadify使用介绍。
http://www.uploadify.com/demos/
根据官方的demo设置html中的内容,

<link href="<%:
Url.Content("~/Content/uploadify/uploadify.css") %>"
type="text/css" rel="stylesheet" />

<script type="text/javascript"
src="<%: Url.Content("~/Content/uploadify/swfobject.js")
%>"></script>

<script type="text/javascript"
src="<%:
Url.Content("~/Content/uploadify/jquery.uploadify.v2.1.4.min.js")
%>"></script>

<script
type="text/javascript">

$(function () {

$.ajaxSetup({

cache: false

});

$("#Attachment").attr("readonly",
"readonly");

$('#file_upload').uploadify({

'uploader': '<%:
Url.Content("~/Content/uploadify/uploadify.swf") %>',

'script': '<%:
Url.Action("UploadFile") %>',

'cancelImg': '<%:
Url.Content("~/Content/uploadify/cancel.png") %>',

'buttonImg':
'<%: Url.Content("~/Content/uploadify/selectfiles.png")
%>',

'fileDataName': 'uploadfile',

'fileDesc': 'AVI视频文件',

'fileExt': '*.avi',

'sizeLimit':<%:
100 * 1024 * 1024 %>,

'folder': 'Upload/Temp/',

'auto': true,

'width':85,

'height':25,

'onError': function
(event,ID,fileObj,errorObj) {

alert(errorObj.type + ' Error: ' + errorObj.info);

},

'onComplete':
function(event, ID, fileObj, response, data) {

if(response
!= ""){

$("#Attachment").val(response);

}else{

alert("上传失败!");

}

}

});

});

</script>

<input
id="file_upload" type="file"
name="uploadfile"/>

需要注意以下内容:

script,指向的地址必须以/开头,否则找不到。

folder,目标文件夹,通过Request.Params["folder"]获取的值是当前网页文件夹+folder设置的文件夹,使用mvc的时候,会导致把controller地址写上,这就不对了,所以我建议不设置这个参数,而是在处理程序指定目录。

fileDataName,设置这个参数,处理程序就可以通过Request.Params["指定名称"]来获取文件了。

'fileDesc':
'AVI视频文件',

'fileExt': '*.avi',

buttonImg,用户指定按钮图片,把图片做成一个带中文字的“选择文件”。

设置服务器端处理代码,以ASP.NET
MVC3为例

[HttpPost]

public string
UploadFile(HttpPostedFileBase uploadfile)

{

if (uploadfile != null)

{

if
(!Directory.Exists(pathTemp))

{

Directory.CreateDirectory(pathTemp);

}

string newFileName =
Guid.NewGuid().ToString("N") +
uploadfile.FileName.Substring(uploadfile.FileName.LastIndexOf('.'));

uploadfile.SaveAs(pathTemp +
newFileName);

return newFileName;

}

else

{

return "";

}

}

错误分析:

Http Error:500。请检查目标路径是否可以写入,添加一个everyone允许完全控制。

Http Error:忘记代码了,就是script目标地址没以/开头导致的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: