Forum Moderators: open
Problem: User must wait for us to tell them that we cannot expect their image. We have clearly indicated what the limits are; however, certain clients do not know how to verify the size of their image.
Is there a quicker way of checking a file size without have to upload it.
1) If they are using Windows, right click and go to properties, the size will be listed there
2) If they are using Mac, control-click ---> Get info (or Command + I). THe size will be listed there.
This would be the easiest, and this leaves it up to the customer. If they can't follow simple instructions, who's fault is it?
[EDITED I did not understand yor post completely, after re-reading it, I do... What WAS here was a way to check the size of the document they are working in]
I did a google and found it can be done, but they will have to agree to allow the ActiveX plugin. I don't know what browsers this will support:
<html>
<head>
<script language="JavaScript">
function A()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>
The browser security does not allow the scripts (Javascript/VBScript) or even applets and ActiveX Controls to read files from the local hard disk. You can only read files if your code is signed by some Certificate Authority (CA). Now the input type "FILE" also does not have the permission to read files. We cannot do anything about that since thats what HTML says. So since it cannot read files, it cannot find the size of the file with which the input tag is associated. Since it cannot find the file size, there is no function exposed by JavaScript/VBScript to return the file size. But if you need to find the file size, say in order to restrict the size of the file uploaded to your web-server. Then you can do so by counting the file contents on the server-side, once the user submits it to the server. Thats what many of the free e-mail providers like www.hotmail.com do.
If you may use a PHP script it can and is easily done by using functions that are included in the GD graphic library.
When an user try to upload an image the script will read the pic and define if the format is the predefined format (that you decided on) then depending on script sophistication you may either ask you user to go back and tweak its own image or you direct the user to a new section of the script that will properly resize the new image and even offer if needed a thumbnail
Post in PHP
Regards
Henry
Thanks for the tip; but activeX is not an option as most of my target market will not have this plugin...
I will forward the PHP tip to the developers and see what happens...