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目标地址没以/开头导致的。
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目标地址没以/开头导致的。
相关文章推荐
- Jquery-uploadify多文件上传插件使用介绍
- jQuery上传插件Uploadify使用介绍
- wget爬虫软件使用介绍
- Linux rpm 命令参数使用详解[介绍和应用]
- 关于使用LoadRunner对Appeon Web应用进行压力测试的初步介绍
- GLib介绍与使用
- assert.h使用介绍
- mathnet 使用方法介绍
- php正则表达式使用的详细介绍
- WebService 应用- .Net 平台WebService的创建、部署和使用介绍(转)
- Memcached的介绍、安装和使用
- 微软的帮助文档,详细的介绍VS开发工具的使用
- Material Design新控件的使用介绍
- 前端构建工具gulpjs的使用介绍及技巧
- C++ 标准模板库STL 双端队列 deque 使用方法与应用介绍(一)
- JS中Date日期函数中的参数使用介绍
- Javascript 高阶函数使用介绍
- Android_AnimationDrawable介绍及使用
- MongoDB工具MagicMongoDBTool使用介绍(一) -- 简单MongoDB入门
- [置顶] iOS开发——布局框架Masonry的介绍与使用