带FLASH插件图片上传
客户端:
<script type=
"
text/javascript
">
$(document).ready(function()
{
$( " #uploadify ").uploadify({
' uploader ': ' JS/jquery.uploadify-v2.1.0/uploadify.swf ',
' script ': ' UploadHandler.ashx ',
' cancelImg ': ' JS/jquery.uploadify-v2.1.0/cancel.png ',
' folder ': ' UploadFile ',
' queueID ': ' fileQueue ',
' auto ': false,
' multi ': true,
' onComplete ':function( event,queueId,fileObj,response,data)
{
// alert(response);
$( " #testimg ").attr( " src ",response);
// alert($("#testimg").attr("src"));
}
});
});
</script>
$(document).ready(function()
{
$( " #uploadify ").uploadify({
' uploader ': ' JS/jquery.uploadify-v2.1.0/uploadify.swf ',
' script ': ' UploadHandler.ashx ',
' cancelImg ': ' JS/jquery.uploadify-v2.1.0/cancel.png ',
' folder ': ' UploadFile ',
' queueID ': ' fileQueue ',
' auto ': false,
' multi ': true,
' onComplete ':function( event,queueId,fileObj,response,data)
{
// alert(response);
$( " #testimg ").attr( " src ",response);
// alert($("#testimg").attr("src"));
}
});
});
</script>
服务器端:
public
void ProcessRequest(HttpContext context)
{
context.Response.ContentType = " text/plain ";
context.Response.Charset = " utf-8 ";
HttpPostedFile file = context.Request.Files[ " Filedata "];
string exname = file.FileName.Substring(file.FileName.LastIndexOf( ' . '), 4); // 包含了点号
string filename = file.FileName.Substring( 0, file.FileName.LastIndexOf( ' . '));
filename = filename + " _ " + System.DateTime.Now.Second.ToString() + exname;
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request[ " folder "])+ " \\ ";
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + filename);
// 下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write(@context.Request[ " folder "]+ " / " + filename);
}
else
{
context.Response.Write( " 0 ");
}
}
{
context.Response.ContentType = " text/plain ";
context.Response.Charset = " utf-8 ";
HttpPostedFile file = context.Request.Files[ " Filedata "];
string exname = file.FileName.Substring(file.FileName.LastIndexOf( ' . '), 4); // 包含了点号
string filename = file.FileName.Substring( 0, file.FileName.LastIndexOf( ' . '));
filename = filename + " _ " + System.DateTime.Now.Second.ToString() + exname;
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request[ " folder "])+ " \\ ";
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + filename);
// 下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write(@context.Request[ " folder "]+ " / " + filename);
}
else
{
context.Response.Write( " 0 ");
}
}