Jump to content

Uploading Images/create Thumbnails


9911782

Recommended Posts

Hi

 

I've been trying to Uploading Images/create Thumbnails to insert into my DB. I get so many errors when running this code.

 

Here is My code:

==================

<?php //@Language=VBScript?>

<?php include("../Connections/fetwebsite.php");

if($_REQUEST["enter"]=="yes" ){

include("../connections/fetwebsite.php");

$sql="select MAX(ImageID) as maximageid from galleryImages";

//execute sql statements

$rsUsers = mysql_query($sql, $fetcolleges) or die(mysql_error());

$rows_rsUsers = mysql_fetch_assoc($rsUsers);

$total_num_Users = mysql_num_rows($rsUsers);

$maximageid = $rows_rsUsers['maximageid'];

$GalleryID = $_REQUEST['GalleryID'];

$ImageID=$_REQUEST["ImageID"];

$Caption = $_POST["caption"];

$GalleryID = $_POST['GalleryID'];

$ImageStatus = $_POST['ImageStatus'];

$ImageFull = $_FILES['ImageFull']['ImageFull'];

$tmpNameFull  = $_FILES['ImageFull']['tmp_name'];

$ImageThumb = $_FILES['ImageThumb']['ImageThumb'];

$tmpNameThumb  = $_FILES['ImageThumb']['tmp_name'];

    $fileName = $_FILES['ImageThumb']['name'];

$tmpName  = $_FILES['ImageThumb']['tmp_name'];

$tmpName2  = $_FILES['ImageThumb']['tmp_name']; 

    $file_size = $_FILES['ImageThumb']['size'];

    $fileType = $_FILES['ImageThumb']['type'];

$DateAdded=date("Y/m/d H:i:s");

// you can change this to any directory you want

// as long as php can write to it

$uploadDir = '../photogalleries/';

//$DefaultPasswords['program'] = crypt('program');

    // the files will be saved in filePath 

  /// $filePath = $uploadDir . $fileName;

  $maximageid = $maximageid + 1;

  $ImageThumb = "thumb"."_".$maximageid."."."jpg";

  $ImageFull =  "photo"."_".$maximageid."."."jpg";

    $filePath = $uploadDir . $fileName;

  $filePath2 = $uploadDir . $ImageThumb;

  $filePath3 = $uploadDir . $ImageFull;

 

  ///RESIZE THUMBNAIL///

  // Set a maximum height and width

$width = 115;

$height = 147;

 

// Get new dimensions

list($width_orig, $height_orig) = getimagesize($filePath);

$ratio_orig = $width_orig/$height_orig;

 

if ($width/$height > $ratio_orig) {

  $width = $height*$ratio_orig;

} else {

  $height = $width/$ratio_orig;

}

// Resample

$image_p = imagecreatetruecolor($width, $height);

$image = @imagecreatefromjpeg($filePath);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

 

// Output

$thumbsize = imagejpeg($image_p, null, 100);

$thumbsize;

if (function_exists('imagecreatefromjpeg') || function_exists('imagecreatetruecolor') || function_exists('imagecopyresampled') || function_exists('getimagesize')) {

  echo 'OK, you already have GD library installed';

} else {

  echo 'Sorry, it seem that GD library is not installed/enabled';

}

///END RESIZE THUMBNAIL///

    // move the files to the specified directory

    // if the upload directory is not writable or

    // something else went wrong $result will be false   

//$result    = move_uploaded_file($tmpName, $filePath); 

$result1    = move_uploaded_file($tmpNameThumb, $filePath3);

$result2    = move_uploaded_file($tmpNameFull, $filePath2); 

 

    if(!get_magic_quotes_gpc())

    {

      $fileName  = addslashes($fileName);

      $filePath  = addslashes($filePath);

    }

 

$uploadDir = '../photogalleries/$fileName';

 

$sql="INSERT INTO galleryImages(Caption,GalleryID, ImageStatus, name,size, type, path,DateAdded,ImageThumb,ImageFull) values ('$Caption','".$_REQUEST['GalleryID']."','$ImageStatus','$fileName', '$file_size', '$fileType', '$filePath','$DateAdded','$ImageThumb','$ImageFull')";

$execute = mysql_query($sql, $fetcolleges) or die(mysql_error());

if($execute){

mysql_close($fetcolleges);

//header("Location: galleryImages_setup.php");

}

}

?>

==================

 

These are the errors I get:

 

=======

Warning: getimagesize(../photogalleries/darkie_02.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\Program Files\Business Objects\ThirdParties\apache\htdocs\fetcolleges\admin\galleryImages_upload.php on line 68

 

Warning: Division by zero in C:\Program Files\Business Objects\ThirdParties\apache\htdocs\fetcolleges\admin\galleryImages_upload.php on line 70

 

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\Business Objects\ThirdParties\apache\htdocs\fetcolleges\admin\galleryImages_upload.php on line 78

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Program Files\Business Objects\ThirdParties\apache\htdocs\fetcolleges\admin\galleryImages_upload.php on line 80

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\Program Files\Business Objects\ThirdParties\apache\htdocs\fetcolleges\admin\galleryImages_upload.php on line 83

============

 

I have GD library installed, and check the php.ini all is well, but still getting this erros. I dont know what to do now.

 

Ps help me!

 

 

Link to comment
https://forums.phpfreaks.com/topic/78918-uploading-imagescreate-thumbnails/
Share on other sites

Hi HaLo2FrEeEk

 

I dont understand you now. Because the code I posted here is the very same post that is giving me the errors I posted.Here is the Code:

 

Here is My code:

==================

<?php //@Language=VBScript?>

<?php include("../Connections/fetwebsite.php");

if($_REQUEST["enter"]=="yes" ){

  include("../connections/fetwebsite.php");

      $sql="select MAX(ImageID) as maximageid from galleryImages";

      //execute sql statements

      $rsUsers = mysql_query($sql, $fetcolleges) or die(mysql_error());

      $rows_rsUsers = mysql_fetch_assoc($rsUsers);

      $total_num_Users = mysql_num_rows($rsUsers);

  $maximageid = $rows_rsUsers['maximageid'];

  $GalleryID = $_REQUEST['GalleryID'];

  $ImageID=$_REQUEST["ImageID"];

  $Caption = $_POST["caption"];

  $GalleryID = $_POST['GalleryID'];

  $ImageStatus = $_POST['ImageStatus']; 

  $ImageFull = $_FILES['ImageFull']['ImageFull'];

  $tmpNameFull  = $_FILES['ImageFull']['tmp_name'];

  $ImageThumb = $_FILES['ImageThumb']['ImageThumb'];

    $tmpNameThumb  = $_FILES['ImageThumb']['tmp_name'];

    $fileName = $_FILES['ImageThumb']['name'];

  $tmpName  = $_FILES['ImageThumb']['tmp_name'];

  $tmpName2  = $_FILES['ImageThumb']['tmp_name'];   

    $file_size = $_FILES['ImageThumb']['size'];

    $fileType = $_FILES['ImageThumb']['type'];

  $DateAdded=date("Y/m/d H:i:s"); 

  // you can change this to any directory you want

  // as long as php can write to it

  $uploadDir = '../photogalleries/';

  //$DefaultPasswords['program'] = crypt('program');

    // the files will be saved in filePath 

  /// $filePath = $uploadDir . $fileName;

  $maximageid = $maximageid + 1;

  $ImageThumb = "thumb"."_".$maximageid."."."jpg";

  $ImageFull =  "photo"."_".$maximageid."."."jpg";

    $filePath = $uploadDir . $fileName;

  $filePath2 = $uploadDir . $ImageThumb;

  $filePath3 = $uploadDir . $ImageFull;

 

  ///RESIZE THUMBNAIL///

  // Set a maximum height and width

  $width = 115;

  $height = 147;

 

  // Get new dimensions

  list($width_orig, $height_orig) = getimagesize($filePath);

  $ratio_orig = $width_orig/$height_orig;

 

  if ($width/$height > $ratio_orig) {

      $width = $height*$ratio_orig;

  } else {

      $height = $width/$ratio_orig;

  }

  // Resample

  $image_p = imagecreatetruecolor($width, $height);

  $image = @imagecreatefromjpeg($filePath);

  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

 

  // Output

  $thumbsize = imagejpeg($image_p, null, 100);

  $thumbsize;

  if (function_exists('imagecreatefromjpeg') || function_exists('imagecreatetruecolor') || function_exists('imagecopyresampled') || function_exists('getimagesize')) {

  echo 'OK, you already have GD library installed';

  } else {

      echo 'Sorry, it seem that GD library is not installed/enabled';

  }

  ///END RESIZE THUMBNAIL///

    // move the files to the specified directory

    // if the upload directory is not writable or

    // something else went wrong $result will be false   

  //$result    = move_uploaded_file($tmpName, $filePath);   

  $result1    = move_uploaded_file($tmpNameThumb, $filePath3);

  $result2    = move_uploaded_file($tmpNameFull, $filePath2);         

 

    if(!get_magic_quotes_gpc())

    {

      $fileName  = addslashes($fileName);

      $filePath  = addslashes($filePath);

    }

 

  $uploadDir = '../photogalleries/$fileName';

 

  $sql="INSERT INTO galleryImages(Caption,GalleryID, ImageStatus, name,size, type, path,DateAdded,ImageThumb,ImageFull) values ('$Caption','".$_REQUEST['GalleryID']."','$ImageStatus','$fileName', '$file_size', '$fileType', '$filePath','$DateAdded','$ImageThumb','$ImageFull')";

  $execute = mysql_query($sql, $fetcolleges) or die(mysql_error());

  if($execute){             

      mysql_close($fetcolleges);

      //header("Location: galleryImages_setup.php");     

  }

}

?>

==================

 

Can you explain more about what you mean?

And I also told you to use code tags.  That will help so we don't have to scroll through 2 pages of code, use a code box and it will cut it off to say, 15 lines, then scroll the rest in a div box, it also formats it putting spaces in properly.  Don't just plant your code right on the board.

  • 3 months later...

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.