Forum Moderators: open

Message Too Old, No Replies

Image Size Checker

is there a quick way to check

         

fashezee

8:29 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We allow our customers to upload an image regarding their products. There is a 5MB limit we have established; however, if a customer uploads an image > 5MB; we can only provide the user an error message when 5megs of the file is uploaded.

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.

lZakl

10:48 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



The easiest way? --> List on the site in BIG RED BOLD type:

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>

lZakl

11:06 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



I also read this, it may help... it was pulled directly from a FAQ asking the same question...

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.

henry0

12:55 pm on Dec 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not rely on JS nowadays quite a few users have disabled JS

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

rocknbil

7:36 pm on Dec 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perl does the same thing with perlMagick/ImageMagick, but both of those are server-side, they need something to warn them before uploading.

fashezee

7:43 pm on Dec 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wish I could rely on the big red bold; but from our experience, no matter how thick the bold, users sometimes "click and asl questions later".

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...