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
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?

Link to comment
Share on other sites

  • 3 months later...
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.