views:

385

answers:

6

Hi all,

How do i restrict the image's dimension that is being uploaded via a php script.?

I am using cakephp v 1.2

thanks

+2  A: 

You'll have to wait until the file is uploaded then call getimagesize() to check the dimensions and print an error if it's too big.

You can't check the size before the upload is complete.

Greg
thanks for your help
Gaurav Sharma
+2  A: 

Without something on the client side which can see the file system (like a Java applet), you can't know it in advance.

Best you can do is inspect the file with GetImageSize after it has been uploaded, but before you do anything important with it.

list($width, $height) = getimagesize($_FILES['myfile']['tmp_name']);
Paul Dixon
+2  A: 

Unfortunately you only can check the dimensions after upload with

list($imagewidth, $width) = getimagesize("$myupload");
Henrik P. Hessel
thanks dude, it helped.
Gaurav Sharma
A: 

in php you can grab the file dimensions while the file is being uploaded.

YuriKolovsky
A: 

http://www.phpclasses.org/browse/package/5904.html

Check this....

James
A: 

You might want to use:

  • AS (ActionScript) (aka Flash)
  • Javascript

... to check the dimensions before upload.

Consider always the way of a front-end, PHP should be combined with client-sided tools/languages/apps to make it more efficient. ;)

daemonfire300