Jump to content

[SOLVED] Need assistance with my syntax...


dlebowski

Recommended Posts

I have spent all day working on this and cannot figure this out.  Here is the error that I get:  "function.imagejpeg</a>]: Unable to open 'images//thumbs/SBCB9196A.jpg'".  This would indicate that I am having a problem with getting a value for the $pathToThumbs variable.  No matter what I assign the $Date variable, I cannot get it to find it.  Can someone please let me know if my syntax is wrong?  Thanks for your help.

 

$Date=$_GET['Date'];

//Create variable
$pathToThumbs = "../images/".$Date."/thumbs/"; 

 

 

// save thumbnail into a file
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );

 

 

Link to comment
Share on other sites

Nope.  It didn't work.  I tried that already.  Thanks anyway though.  Here is the whole script.  Keep in mind, everything is working except the thumbnail portion.

 

<?php
$ImageAuctionDate=$_GET['ImageAuctionDate'];

if(is_dir("images/".$ImageAuctionDate."")) {

}
else
{
mkdir("images/".$ImageAuctionDate."", 0777);
}

echo 'Upload result:<br>'; // At least one symbol should be sent to response!!!

$uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/images/".$ImageAuctionDate."/";

$target_encoding = "ISO-8859-1";
echo '<pre>';
if(count($_FILES) > 0)
{
$arrfile = pos($_FILES);
$uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name']));

if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
   echo "File is valid, and was successfully uploaded.\n";

}
else
{
echo 'No files sent. Script is OK!';

echo 'Here is some more debugging info:';
print_r($_FILES);
echo "</pre>";
}
include("dbinfo.inc.php");
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$ImageAuctionDate=$_GET['ImageAuctionDate'];

$pathToImages = "../images/".$ImageAuctionDate."/";
$pathToThumbs = "../images/".$ImageAuctionDate."/thumbs/"; 
$thumbWidth = "75";

function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
  // open the directory
  $dir = opendir( $pathToImages );

  // loop through it, looking for any/all JPG files:
  while (false !== ($fname = readdir( $dir ))) {
    // parse path for the extension
    $info = pathinfo($pathToImages . $fname);
    // continue only if this is a JPEG image
    if ( strtolower($info['extension']) == 'jpg' )
    {
      echo "Creating thumbnail for {$fname} <br />";

      // load image and get image size
      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      $width = imagesx( $img );
      $height = imagesy( $img );

      // calculate thumbnail size
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );

      // create a new temporary image
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );

      // copy and resize old image into new image
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

      // save thumbnail into a file
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
    }
  }
  // close the directory
  closedir( $dir );
}

createThumbs("images/".$ImageAuctionDate."/","images/".$imageAuctionDate."/thumbs/",100);

?>

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.