Forum Moderators: coopster

Message Too Old, No Replies

Get Image Size before upload

Is it possible to get filesize before uploading to server?

         

kunwarbs

1:25 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



I was wandering if it's possible with PHP to get the filesize of the image being uploaded by the user.

I would like to restrict the users from uploading photos more than 2MB of size. Currently I use filesize() function to get the file size but it appears that file is first being uploaded on the server, then checking the size (this takes a few seconds or minute, depending on the filesize) and showing the error accordingly.

Please help me out.

jatar_k

2:54 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



unless you can find some type of client side solution you have to wait until it's uploaded

kunwarbs

3:15 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



unless you can find some type of client side solution you have to wait until it's uploaded

Can it be done using javascript?

jatar_k

3:22 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that would be a place to look though I don't know

amznVibe

3:43 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript by design cannot see local files for security reasons (in most properly secure browsers).

Signed java and activex apps can see files but that's a crazy way to do it.

You can insert a hidden value in your form that some browsers and PHP will obey:

<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

But remember it can be overridden by hackers so always check server side.

[edited by: amznVibe at 3:49 pm (utc) on Nov. 7, 2008]