Forum Moderators: open
function imageSize (pathField, previewName)
{
var str = '';
var path = pathField.value;
document[previewName].src = 'file://'+path.replace(/\\/gi,'/');
var img = new Image();
img.src = 'file://'+path.replace(/\\/gi,'/');
var size_pic = document.getElementById(previewName).fileSize;
str = "File size="+size_pic;
return (str);
}
my HTML who call it:
<form name="myform" method="post" action="<myaction>">
<input name="upload_file" type="file" id="upload_file" size="28" value="" onChange="Javascript:imageSize(document.myform.upload_file,'tmpImg')"><br>
<img src="tmp.gif" name="tmpImg" width="1" height="1"/>
<input type="Submit" name="upload" value=”upload">
</form>
If I test my function offline it always manage correctly. Unfortunately, when I test it online (i.e. when I copy the html with the above javascript on my webserver Apache), it manages only if files I upload are little. Normally it returns -1!
Could someone help me to find the problem?
If I could read file size on **your** computer via the file upload, I could read other files, couldn't I?
You can do this if your code is CA signed, and I've seen some Ajax attempts at solutions, but cannot verify if they work at all or with consistency. It's just not worth it. :-)
Best shot is to read the file size server-side on upload, or implement a Java applet.