因为ie9 不支持 js 验证大小,所以改用ajax 后台做验证 ,不过发现验证了之后,fileupload 的路径消失了 ...不知道哪里出了错 ?
前台 js :
function ajaxFileUpload() {
$.ajaxFileUpload({
url: 'ajax.ashx',
secureuri: false,
fileElementId: 'FileUpload1',
dataType: 'json',
success: function(data, status) {
if (typeof (data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
}
}
},
error: function(data, status, e) {
alert(e);
}
})
}
ashx 后台:
string error = "";
string msg="";
HttpPostedFile file = context.Request.Files[0];
int iFileSize = file.ContentLength;
if (iFileSize > 100000)
//检查images size
{
error = "size limit 100jb";
string result = "{ error:'" + error + "'}";
context.Response.Write(result);
}
else
{
string result = "{ error:'" + error + "'}";
context.Response.Write(result);
}
不是很明白原理,请高人指点丫 ...万分感激
[解决办法]
你想得到客户端的文件完全路径:
string aa = FileUpload1.PostedFile.FileName.ToString();
[解决办法]
file输入是不能重复保持路径的,也不能设置。
如果要验证,你可以考虑使用silverlight在客户端直接读取文件,然后验证完了使用silverlight上传到服务器。例如:http://blog.csdn.net/dujingjing1230/article/details/5443003