Page 1 of 1

How to limit the uploaded image dimensions?

Posted: Mon May 29, 2006 4:17 pm
by Milan
I have the following code to upload image.
Is there an easy way to limit the image dimensions ( and/or file type since i had to hardcode it here to jpg)

Code: Select all

$action = $_POST["action"];
	$max_size = "102400";
	if ($action == 'upload')
{
	
	
	if ($_FILES["filename"]["size"] > $max_size) die ("<b>File too big!  Try again...</b>");
	
	$uname= $_POST['Username'];
	copy($_FILES["filename"]["tmp_name"],"images/userlogo/$uname".$_FILES["filename"][''].'.jpg') or die(mysql_error());
}
thanks!

Posted: Mon May 29, 2006 4:27 pm
by pickle
I'm pretty sure there's no way to restrict image dimensions before submitting the form. You can certainly read the file before processing it - but that has to happen after the upload.

Posted: Mon May 29, 2006 4:29 pm
by Milan
Yes that is what i had on mind. How to do it after i upload the image?

Posted: Mon May 29, 2006 4:37 pm
by pickle

Posted: Mon May 29, 2006 4:42 pm
by Milan
GReat!


thanks!

Posted: Mon May 29, 2006 5:22 pm
by Milan
and in order to resize it i will need a GD lib?

Posted: Mon May 29, 2006 5:25 pm
by pickle
or ImageMagik. IMHO GD is better.