Jump to content

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


cstegner

Recommended Posts

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

[code]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>";

}[/code]
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.