Entry
JavaScript: Is it possible to find the filesize of the attached file (i.e., <input type=file>)?
Sep 12th, 2004 09:39
Knud van Eeden, frequently asked,
----------------------------------------------------------------------
--- Knud van Eeden - 09 October 2001 - 02:57 pm ----------------------
JavaScript: Is it possible to find the filesize of the attached file
(i.e., <input type=file>)?
---
Possible idea:
---
[Internet: source: http://www.google.com, search for 'filesize
javascript':
http://www.xs4all.nl/~ppk/js/filesize.html]
If you can load the file in your browser, you can check the filesize
with
(copy/paste this text in a file, e.g. mytest.htm, then load this file
in your browser):
--- cut here: begin --------------------------------------------------
<HTML>
<HEADER>
<SCRIPT>
function PROCFileSizeCheck() {
var size = ( document.fileSize ) * 1;
var y = document.images;
var imglength = 0;
if ( !document.fileSize ) {
alert('This script does not work in your browser.');
return;
}
for ( i=0; i < y.length; i++ ) {
imglength += ( y[ i ].fileSize ) * 1;
}
var total = size + imglength;
var writestring = 'File size HTML: ' + size;
writestring += '\nFile size images: ' + imglength;
writestring += '\nTotal file size: ' + total;
if ( total > 40000 ) {
writestring += "\nFile too large!";
}
alert( writestring );
}
</SCRIPT>
</HEADER>
<BODY
ONLOAD='
PROCFileSizeCheck();
'
>
</BODY>
</HTML>
--- cut here: end ----------------------------------------------------
---
---
Internet: see also:
---
Can I check the size of a selected file before uploading?
http://www.faqts.com/knowledge_base/view.phtml/aid/1685/fid/177
---
Possible idea:
What you could try to do as a possible workaround is to run an
executable (e.g. written in Java, C++, ...), that checks the filesize
and returns this information to your JavaScript program somehow
[Internet: see also:
http://www.faqts.com/knowledge_base/view.phtml/aid/10323]
---
searching http://www.google.com with the above question gave:
[Internet: see e.g.:
http://www.jguru.com/faq/view.jsp?EID=330134]
----------------------------------------------------------------------