Jump to content


Photo

Passing image file information from form into function, having problems.


  • Please log in to reply
2 replies to this topic

#1 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 14 August 2006 - 01:19 PM

For some reason it wont pass the image variables into the function correctly.
The first if statement in the function keeps stopping it.

Please let me know what I need to do.

Thanks

function mkThumb($image, $project, $newname, $forcedwidth, $forcedheight){
    $maxwidth = 10000;
    $maxheight = 100000;
    $max_filesize = 500000;
    $max_filesize_kb = ($max_filesize / 1024);
    $uploads = 'photos/' . $project . '/';
	$types_array = array('image/gif','image/pjpeg','image/x-png','image/jpeg');

	if($_FILES[$image]['name'] == ""){
	    echo "Please select a file to upload!";
	    exit;
	}
	if(!in_array($_FILES[$image]['type'], $types_array)){
	    echo "That file type is not allowed!";
	    exit;
	}
	if($_FILES[$image]['size'] > $max_filesize){
	    echo "Your file is too large. <br />Files may be up to ".$max_filesize_kb."kb";
	    exit;
	}
    $imagesize = getimagesize($_FILES[$image]['tmp_name']);
    $imagewidth = $imagesize[0];
    $imageheight = $imagesize[1];

	if($imagewidth > $maxwidth || $imageheight > $maxheight){
	    echo "Your file is too large. (".$imagewidth." x ".$imageheight.")<br>The maximum is <b>".$maxwidth." x ".$maxheight."</b> pixels.";
	    exit;
	}

	$ext = explode(".",$_FILES[$image]['name']);
	$imagename = $newname . '.' . 'jpg';
	$thname = $newname . "st" . "." . "jpg";
	move_uploaded_file($_FILES[$image]['tmp_name'], $uploads.'/'.$imagename)
	or die ("Couldn't upload ".$_FILES[$image]['name']."\n");

	// Make thumbnail

	$sourcefile = $uploads . $thname;
	$forcedwidth = "175";
	$forcedheight = "175";
	$destfile = 'thumbs/' . $project . '/' . $imagename;

    $fw = $forcedwidth;
    $fh = $forcedheight;
    $is = getimagesize( $sourcefile );
    if( $is[0] >= $is[1] )
    {
        $orientation = 0;
    }
    else
    {
        $orientation = 1;
        $fw = $forcedheight;
        $fh = $forcedwidth;
    }
    if ( $is[0] > $fw || $is[1] > $fh )
    {
        if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) )
        {
            $iw = $fw;
            $ih = ( $fw / $is[0] ) * $is[1];
        }
        else
        {
            $ih = $fh;
            $iw = ( $ih / $is[1] ) * $is[0];
        }
        $t = 1;
    }
    else
    {
        $iw = $is[0];
        $ih = $is[1];
        $t = 2;
    }
    if ( $t == 1 )
    {
        $img_src = imagecreatefromjpeg( $sourcefile );
        $img_dst = imagecreatetruecolor( $iw, $ih );
        imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );
        if( !imagejpeg( $img_dst, $destfile, 90 ) )
        {
            exit( );
        }
    }
    else if ( $t == 2 )
    {
        copy( $sourcefile, $destfile );
    }
}
// End of mkThumb function

if(isset($_POST['addProject'])){
  
  //add to database
  mysql_query("INSERT INTO 'select' ('project','title', 'description') VALUE ('$title', '$description')");

  //create and place images and thumbs
  
  if($_FILES['image1'] != ""){
    mkThumb($image1, $project, '1', '50', '50');
    echo "<span style='color: yellow'>Added 1</span>";
  }  
  if($_FILES['image2'] != ""){
    mkThumb($image2, $project, '2', '50', '50');
    echo "<span style='color: yellow'>Added 2</span>";
  }  
  if($_FILES['image3'] != ""){
    mkThumb($image3, $project, '3', '50', '50');
    echo "<span style='color: yellow'>Added 3</span>";
  }  
  if($_FILES['image4'] != ""){
    mkThumb($image4, $project, '4', '50', '50');
    echo "<span style='color: yellow'>Added 4</span>";
  }  
  if($_FILES['image5'] != ""){
    mkThumb($image5, $project, '5', '50', '50');
    echo "<span style='color: yellow'>Added 5</span>";
  }  
  if($_FILES['image6'] != ""){
    mkThumb($image6, $project, '6', '50', '50');
    echo "<span style='color: yellow'>Added 6</span>";
  }  
  if($_FILES['image7'] != ""){
    mkThumb($image7, $project, '7', '50', '50');
    echo "<span style='color: yellow'>Added 7</span>";
  }  
  if($_FILES['image8'] != ""){
    mkThumb($image8, $project, '8', '50', '50');
    echo "<span style='color: yellow'>Added 8</span>";
  }

  echo "<span style='color: yellow'>Added</span>";

}


#2 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 15 August 2006 - 06:17 PM

Can anyone help?  Really need to figure this out.

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 August 2006 - 06:21 PM

Do you have the correct entype set in your form?

It should be set to "multipart/form-data".




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users