How to limit the uploaded image dimensions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

How to limit the uploaded image dimensions?

Post 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!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

Yes that is what i had on mind. How to do it after i upload the image?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

GReat!


thanks!
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

and in order to resize it i will need a GD lib?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

or ImageMagik. IMHO GD is better.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply