日期:2014-05-17 浏览次数:20481 次
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
HttpPostedFile file = context.Request.Files["fileData"];
string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]);
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(Path.Combine(uploadPath, file.FileName));
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
context.Response.Write("1");
//context.Response.Write("1|222"); //标志位1标识上传成功,后面的可以返回前台的参数,比如上传后的路径等,中间使用|隔开
}
else
{
context.Response.Write("0");
}
}
<div id="fileQueue" class="fileQueue"></div>
<input id="testFileInput" type="file" name="image"
uploader="uploadify/scripts/uploadify.swf"
cancelImg="uploadify/cancel.png"
script="Ajax/UploadHandler.ashx"
scriptData="{PHPSESSID:'xxx', ajax:1}"
fileQueue="fileQueue"
folder = "/UpFiles"
onAllComplete="uploadifyAllComplete"
fileDataName="file"
auto= "false"
fileExt="*.jpg;*.jpeg;*.gif;*.png;"
fileDesc="*.jpg;*.jpeg;*.gif;*.png;"/>
</div>
HttpPostedFileBase FileData = Request.Files["fileData"];