uploadfy|ajax flash 上传插件
1.引用脚本样式
<script src="/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<link href="/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
2.添加file标签
<input id="uploadImg" type="file" />
3.初始化
$("#uploadImg").uploadify({
'swf': '/uploadify.swf',
'checkExisting': false,
'uploader': '/handler/UploadHandler.ashx',
'cancelImage': '/uploadify/cancel.png',
'buttonText': '请选择要上传的文件',
'fileExt': '*.jpg;*.gif;*.png',
'width': 150,
'auto': true,
'multi': false,
'uploadLimit': 9999,
'postData': { 'filepath': '/case/' },
'onUploadSuccess': function (file, data, response) {
if (data) {
$("#imghead").attr("src", data);
}
}
});
4.服务器端
public void ProcessRequest(HttpContext context) { string returnUrl = string.Empty; string filepath = context.Request.Form["filepath"]; HttpPostedFile file = context.Request.Files["FileData"]; if (file != null) { try { string fileName = DateTime.Now.ToString("yyyyMMddhhmmss"); string extensionName = Path.GetExtension(file.FileName.Trim()); string _path = string.Empty; DateTime _n = DateTime.Now; if (string.IsNullOrEmpty(filepath)) _path = "/uploadimg/" + _n.Year.ToString() + _n.Month.ToString() + _n.Day.ToString() + "/"; else _path = filepath + _n.Year.ToString() + _n.Month.ToString() + _n.Day.ToString() + "/"; FtpUpload ftp = new FtpUpload(_path + fileName + "_0" + extensionName); ftp.UploadFile(file.InputStream); returnUrl = ftp.HttpFtpServerUrl; } catch (Exception ex) { } } else { context.Response.Write("0"); } }

浙公网安备 33010602011771号