Can anyone help me in this: How to limit file size before uploading it?
This script works fine, but you have to configure first your browser to make the alert window appear. Which is not good at all This script only runs in IE6/7/8.
function IELimmit(calculate)
{
var myFSO = new ActiveXObject(“Scripting.FileSystemObject”);
var filepath = document.calculate.uploaded_file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
if (size > 2097152) {
alert ("Unable to proceed upload, File is larger than 2mb.\
Please upload only files less than 2mb.");
//document.calculate.uploaded_file.value = “”;
//document.calculate.uploaded_file.focus();
return false;
}
return true;
}
---->Any help how to make the alert window appear without any browser configurations??? Thanks in Advance!
Thanks for your reply, but I think I already tried this approach, I want an alert window that informs user that the file they want to upload exceeds the file size limit… any Idea with this?
It’s an honest comment though. There is no realistic way to achieve what you’re after, thereby resulting only in unrealistic means. by which to achieve it.
When the impossible has been ruled out, only the improbable remains - Shirlock Holmes (brother)
There isn’t a way. Security features implemented into browsers specifically prohibit JavaScript from being able to find out anything about files.
The only way to even attempt to block large files being uploaded is the hidden field I mentioned earlier - that is the ONLY option that works and then only sometimes.
You must check the filesize on the server immediately after uploading if you want to limit file size. The only way to do that and produce an alert is to do an ajax call to the server after the file has had time to upload to request a file size check and then produce the alert if the uploaded file is too big.