I Had a file upload control I want that file will attach only when it is below under some Memory Limit (8 Mb). I get the file size using Ajax and call it on the onchange event. But I am not able to restrict the attachment of files. Can any one Help me ?
This is the example code
function a(obj) {
if ($(obj).val() != '') {
var request;
var flag = false;
request = $.ajax({
type: "POST",
url: 'CheckFileSize.aspx',
data: "search=" + $(obj).val(),
success: function (size) {
if (parseFloat(size) < 8192) {
flag = true;
}
if (!flag) {
alert('File size is greater then 8 MB. The size of the file is ' + (parseFloat(size)) / 1024 + ' MB');
//Doing something that restrict user from upload enter code here
$(obj).val(null);
}
return flag;
}
});
}
return false;
}
In your server-side method where you process the uploaded file, add this code:
Adding the following to the system.web section of the web.config file will also prevent over-large uploads from being accepted.