Jump to content

[SOLVED] image size question


justAnoob

Recommended Posts

my size check is not working properly,,, am I missing something?

 

<?php
if(isset($_POST['submit']))
{
$image=$_FILES['image']['name'];
if($image) 
{
	$filename = stripslashes($_FILES['image']['name']);
	$extension = getExtension($filename);

	$extension = strtolower($extension);
	if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png"))
	{
		$_SESSION['badformat'] = "Your picture must be a .JPG .GIF or .PNG";
		header("location: http://www.---------.com/--------.php");
		$errors=1;
		exit();

	}

                          list($width, $height, $type, $attr) = getimagesize("$image");
	if($height > $width)
	{
	    echo "Your pictures height is larger than its width. Please resize your picture.";
	    $errors=1;
	    exit();
	}          



	else
	{
		$size=filesize($_FILES['image']['tmp_name']);
		if ($size > MAX_SIZE*1024)
		{
			$_SESSION['toobig'] = "Your picture can not exceed 1.5 megabyte.";
			header("location: http://www.------.com/---------.php");
			$errors=1;
			exit();
		}

		$image_name=time().'.'.$extension;
		$newname="userimages/$category/".$image_name;
		$copied = copy($_FILES['image']['tmp_name'], $newname);
		if (!$copied)
		{
			$_SESSION['notcopy'] = "There was an error posting your picture. Please try again later.";
			header("location: http://www.-------.com/-------.php");
			$errors=1;
			exit();

		}
	}
}
}
?>

 

Link to comment
Share on other sites

Oh, sorry. I'm looking to keep images widescreen or square format... No crazy, tall stretch pictures. Also just check to make sure it is an image... What I have below is not working... A picture that is taller than its width is not catching the error that I have below.

<?php
list($width, $height, $type, $attr) = getimagesize("$image");
if($height > $width)
{
   echo "Your pictures height is larger than its width. Please resize your picture.";
   $errors=1;
   exit();
}          
?>

Link to comment
Share on other sites

Still no luck,,,I've searched google and it seems that others have pretty much what I got here... Everthing else works great other than checking the image size. I have tried $image and $filename for the getimagesize..

<?php
session_start();
include "connection.php";

$item_name = mysql_real_escape_string($_POST['item_name']);
$description = mysql_real_escape_string($_POST['description']);
$in_return = mysql_real_escape_string($_POST['in_return']);
$category = mysql_real_escape_string($_POST['listmenu']);

define ("MAX_SIZE","1500");
function getExtension($str)
{
   $i = strrpos($str,".");
   if (!$i)
  {
     return "";
  }
  $l = strlen($str) - $i;
  $ext = substr($str,$i+1,$l);
  return $ext;
}
$errors=0;
if(isset($_POST['submit']))
{
   $image=$_FILES['image']['name'];
   if($image) 
   {
      $filename = stripslashes($_FILES['image']['name']);

      list($width, $height, $type, $attr) = getimagesize($filename);
      if($height > $width)
      {
         echo "Your pictures height is larger than its width. Please resize your picture.";
         $errors=1;
         exit();
      }          

      $extension = getExtension($filename);
      $extension = strtolower($extension);
      if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png"))
      {
         $_SESSION['badformat'] = "Your picture must be a .JPG .GIF or .PNG";
         header("location: http://www.--------.com/-------.php");
         $errors=1;
         exit();
      }
      else
      {
         $size=filesize($_FILES['image']['tmp_name']);
         if ($size > MAX_SIZE*1024)
         {
            $_SESSION['toobig'] = "Your picture can not exceed 1.5 megabyte.";
            header("location: http://www.---------.com/------.php");
            $errors=1;
            exit();
         }
         $image_name=time().'.'.$extension;
		$newname="userimages/$category/".$image_name;
		$copied = copy($_FILES['image']['tmp_name'], $newname);
		if (!$copied)
		{
			$_SESSION['notcopy'] = "There was an error posting your picture. Please try again later.";
			header("location: http://www.-------.com/--------.php");
			$errors=1;
			exit();

		}
	}
}
}

// if everything is good, post picture for the user
$mysqlcategory = $category;
$imgpath = $newname;
$findit = $_SESSION['id'];
$result=mysql_query("SELECT id FROM members WHERE username = '$findit'");
$row=mysql_fetch_assoc($result);
$user_id = $row['id'];
$sql = "INSERT INTO abcxyz(item_name, description, in_return, imgpath, category, user_id)VALUES('$item_name','$description','$in_return', '$imgpath', '$mysqlcategory', '$user_id')";
mysql_query($sql) or die(mysql_error());
// go to confirmation page if upload is completed.
if(isset($_POST['submit']) && !$errors)
{
$_SESSION['posted'] = $item_name;
$_SESSION['picposted'] = $imgpath;
header("location: http://www.-------.com/-------.php");
exit();
} 
?>

Link to comment
Share on other sites

Also another question.. With my upload script it assigns each picture a name using time()...Each user can upload pictures. All the pictures are viewable, about 125x125 pixels. Then if the image is clicked,, a full size picture is viewable. The question is,,, my upload script uploads the picture at whatever size it is..Should I create thumbnail pics to have displayed in the 125x125 areas and then when they are clicked, it would open the full size images???   

 

My folder setup on my server is like this....

userimages/category1

userimages/category2

etc........

 

So would I have to also have a thumnail folder for all the thumbs?

userimages/thumbs/category1

userimages/thumbs/category2

etc.......

 

Wouldn't this just take up more space on the server?? What is the best way to go about this?

Link to comment
Share on other sites

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.