<div class="item form-group">
<div class="col-sm-12 col-md-12 col-xs-12 ">
<div class="compose-textarea">
<div class="file-loading">
<input id="File" class="file" type="file" />
</div>
</div>
</div>
</div>
$('#File').fileinput('refresh', {
uploadUrl: "FileUploadHandler.ashx?upload=Instruction",
allowedFileExtensions: ['pdf'],//允许上传文件类型
}).on("fileuploaded", function (event, data) {
//上传后执行的改变
});
public class FileUploadHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
private static string path;
public System.Collections.ArrayList arrExtensions = new System.Collections.ArrayList();
public void ProcessRequest(HttpContext context)
{
//new LogFile<FileUploadHandler>().Error("###### Excute Upload DBUpgrade");
Array FileExtensions = GetExtensions();
const int maxSize = 1500000;
try
{
BPMSServerConfigControl server = new BPMSServerConfigControl();
string filenameStr = context.Request.Form["filename"];
if (context.Request.QueryString["upload"] == "Instruction")
{
UploadResponse resp = new UploadResponse();
string fname ="1.pdf";//文件名称
string savePath = AppDomain.CurrentDomain.BaseDirectory + "PDF\\"+ fname;//文件路径
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "PDF")) //判断文件存放路径是否存在
{
Directory.CreateDirectory(savePath);
}
// (1)获取上传的文件,保存到 应用程序基目录
HttpPostedFile postedFile = context.Request.Files[0];
postedFile.SaveAs(savePath);
context.Response.ContentType = "text/html";
context.Response.Write(new JavaScriptSerializer().Serialize(resp));
}
}
catch (Exception ex)
{
}
}
}