By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,901 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,901 IT Pros & Developers. It's quick & easy.

getting image width/height before uploading

P: n/a
ok
Hello,

Q: How do I get image width and height before uploading an image?
This because, I want to restrict people uploading huge files.
Thanks in advance

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ok wrote:
Hello,

Q: How do I get image width and height before uploading an image?
This because, I want to restrict people uploading huge files.


You can't with PHP. You'd have to get some kind of javascript to do it
since it would be client-side _before_ uploading. However, I usually
handle it by uploading the file, then using GD to resize it
appropriately. The only restriction you'd set then is the max file size
to upload.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2

P: n/a
Hi,

Afaik there is no way to get the image (or any other file)-data
such as size, height, length etc with php before uploading.
PHP is executed on the server, so it has no rights to access
files on the client machine.
You have two possibilities, you can load the image in your page
from the client and check the height and width with javascript,
what i don't recommend, because javascript depends on the browser
software of the client.
The second is to upload the file anyway (which will be loaded into
a temp-directory), check it then, and if ok, you can save it where
you want to save it on the server.
To avoid that any user uploads a image whichis really too big, you
have the server or php.ini configurations to set the max_file_size
or a timeout of the script.

Greetz
Paul.
Jul 17 '05 #3

P: n/a
sk
This is probably the way to go, though now that the file is on your
server for poking and prodding, you can use the same image functions to
resize it down to your preferred maximum size and maybe convert it (if
they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
uniform format.

--
Steve Koppelman

Paul Wellner Bou wrote:
....
The second is to upload the file anyway (which will be loaded into
a temp-directory), check it then, and if ok, you can save it where
you want to save it on the server.
To avoid that any user uploads a image whichis really too big, you
have the server or php.ini configurations to set the max_file_size
or a timeout of the script.

Greetz
Paul.


Jul 17 '05 #4

P: n/a
sk TOP-POSTED when he wrote:
Paul Wellner Bou wrote:
...
The second is to upload the file anyway (which will be loaded into
a temp-directory), check it then, and if ok, you can save it where
you want to save it on the server.
To avoid that any user uploads a image whichis really too big, you
have the server or php.ini configurations to set the max_file_size
or a timeout of the script.


This is probably the way to go, though now that the file is on your
server for poking and prodding, you can use the same image functions to
resize it down to your preferred maximum size and maybe convert it (if
they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
uniform format.


Maybe it's just me, but isn't that what I had said in the first place?
Maybe nobody is getting/reading my messages?

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #5

P: n/a
Justin Koivisto wrote:
sk TOP-POSTED when he wrote:
Paul Wellner Bou wrote:
...
The second is to upload the file anyway (which will be loaded into
a temp-directory), check it then, and if ok, you can save it where
you want to save it on the server.
To avoid that any user uploads a image whichis really too big, you
have the server or php.ini configurations to set the max_file_size
or a timeout of the script.


This is probably the way to go, though now that the file is on your
server for poking and prodding, you can use the same image functions to
resize it down to your preferred maximum size and maybe convert it (if
they uploaded a BMP or a GIF and you just want JPEGs or PNGs) to a
uniform format.


Maybe it's just me, but isn't that what I had said in the first place?
Maybe nobody is getting/reading my messages?


Or maybe, just maybe, you could let them upload the file first, THEN decide
if it's too big, etc....

;p <grin>

Don't know if anyone has pointed this out yet, but
1 - you can set the max size for an uploaded file in php.ini
2 - although it may/may not be supported by the browser, you can set
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.