Jump to content

image upload trying to validate img type and with and height??? HELP PLEASE


alphasurf

Recommended Posts

Hi all I am new on this site. I need help please I have been stuck on this for days. I am trying to validate the image upload so the user can only upload .jpg or .gif with a max width of 800 and max height of 800. Here is my code. Thanks all for any help.  ???
[code]
<?
require_once("conn.php");
require_once("includes.php");

if(isset($_POST[s1]))
{
//Trying to limit upload to .gif and .jpg only--->

        if(!ereg("gif$", $_FILES) && !ereg("jpg$", $_FILES))
        {
                $pix_error = "<center><font color=red size=2 face=verdana><b>You can upload only image files!</b></font></center>";
        }

$imgSize = getimagesize($_FILES);

      $imgSize[0] = 800;
      $imgSize[1] = 800;

      //Will be False if the file is not an image.


  if ($imgSize === false) {
      $error = "<center><font color=red size=2 face=verdana><b>Max width is 800 Max height is 800!</b></font></center>";
  }

if($imgSize[2] != IMG_GIF || $imgSize[2] != IMG_JPG) {
    $error = "<center><font color=red size=2 face=verdana><b>Only gif or jpg images</b></font></center>";
}



//End of my validation--->


        if(!empty($_FILES[images][name][0]))
        {
                while(list($key,$value) = each($_FILES[images][name]))
                {
                        if(!empty($value))
                        {
                                $NewImageName = $t."_offer_".$value;
                                copy($_FILES[images][tmp_name][$key], "as_images/".$NewImageName);

                                $MyImages[] = $NewImageName;
                        }
                }

                if(!empty($MyImages))
                {
                        $ImageStr = implode("|", $MyImages);

                        if(!empty($_POST[OldImages]))
                        {
                                $ImageStr = $ImageStr."|".$_POST[OldImages];
                        }
                }

        }
        else
        {
                $ImageStr = $_POST[OldImages];
        }

        $catInfo = explode("|", $_POST[SelectCategory]);
        $CategoryID = $catInfo[0];
        $SubcategoryID = $catInfo[1];
        $SubcategoryName = $catInfo[2];

        $q1 = "update a_s set
                                        CategoryID = '$CategoryID',
                                        SubcategoryID = '$SubcategoryID',
                                        SubcategoryName = '$SubcategoryName',
                                        city = '$_POST[city]',
                                        state = '$_POST[state]',
                                        description1 = '$_POST[description1]',
                                        Price = '$_POST[Price]',
                                        description2 = '$_POST[description2]',
                                        Liner = '$_POST[Liner]',
                                        AttentionColor = '$_POST[AttentionColor]',
                                        DetailsColor = '$_POST[DetailsColor]',
                                        Site = '$_POST[Site]',
                                        Website = '$_POST[Website]',
                                        FromMonth = '$_POST[FromMonth]',
                                        FromDay = '$_POST[FromDay]',
                                        ToMonth = '$_POST[ToMonth]',
                                        ToDay = '$_POST[ToDay]',
                                        image = '$ImageStr'

                                        where ListingID = '$_GET[id]' and AgentID = '$_SESSION[AgentID]' ";

        mysql_query($q1);

        if(mysql_error())
        {
                echo mysql_error();
        }
        else
        {

        header("location:info.php?id=$_GET[id]");
        exit();
}
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.