Jump to content

Recommended Posts

hi, so i got this here upload script, its fairly safe... now i am having a hard time implementing a dimension constriction, basically i want my members to be able to upload a 100x100 px image and below but not above.. i have looked around and tried many things but none seem to work, i was hoping someone could help me figure out what the heck i am doing wrong xD.

 

Any and all help would be greatly appreciated!!

 

 

CODE:

if ($_POST['save'])
{

$imageinfo = getimagesize($_FILES['file']['tmp_name']);
if($imageinfo[0] > 100 || $imageinfo[1] > 100 )
{
echo 'um this file cannot complete';
}
else
{
if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") && ($_FILES["file"]["size"] < 102401))
  	{
  		if ($_FILES["file"]["error"] > 0)
    	{
    		echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
   		}
  		else
    	{
	function findexts ($filename)
		{
			$filename = strtolower($filename) ;
			$exts = split("[/\\.]", $filename) ;
			$n = count($exts)-1;
			$exts = $exts[$n];
			return $exts;
		}
		//This applies the function to our file
		$ext = findexts ($_FILES["file"]["name"]); 
		$avatarExtension = $ext;
		$avatarActivate = yes;
		$user1 = 'user';
		//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
		$ran = $user1.$_SESSION['user_id'];
		//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
		$ran2 = $ran.".";
		//This assigns the subdirectory you want to save into... make sure it exists!
		$target = "avatars/";

		include 'connect/config.php';
		include 'connect/newsOpenDb.php';
		$query = 'UPDATE users SET avatarExtension=\'' . mysql_real_escape_string($avatarExtension) . '\', avatarActivate=\'' . mysql_real_escape_string($avatarActivate) . '\'WHERE Username=\'' . $name . '\'';
  			 mysql_query($query) or die('Error : ' . mysql_error());

		include 'connect/closedb.php';

		//This combines the directory, the random file name, and the extension
		$target = $target . $ran2.$ext; 
   			 if (move_uploaded_file($_FILES["file"]["tmp_name"], $target))
  		{
      			echo "<br /><br />Avatar Successfully Uploaded and updated.<br />";
      		}
		else
		{
			echo "Invalid file";
		}
	}
}
}

}

 

thanks a load!!

I found this tutorial good for me when I wanted to add a photo gallery to my website.  You can change the size of the images to a max size.  You can tweek it pretty easily as I did to get the images thumbnails and main pictures the way you want.

 

http://www.sitepoint.com/article/php-gallery-system-minutes

hmm well see, the function of this is for members of my site, where allowed, they can upload an avatar, and the system will spit back if it is too big.. i really dont want a manipulation script as much as where it looks at the image and stops the script and gives an error message if it is over, say 100 by 100 pixels..

 

EDIT:

hmm maybe i will have to do that.....(resizer)

 

sorry for a double post.. but i found something simple xD and i thought i had done this but it works!

 

$tmpName = $_FILES['file']['tmp_name'];
       
list($width, $height, $type, $attr) = getimagesize($tmpName);

if($width>100 || $height>100)
{
die("<br /><br />exceeded image dimension limits.");
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.