• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

What does this error mean?

I've got a script attached that converts an image into a thumbnail. The error that I continue to get is:

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'thumbs' for writing: Is a directory in /home/content/b/r/u/brucegust/html/adm/photo_one_transform.php on line 54


The thumbs directory is set up with "777" as the permissions, so I'm a a loss as to what's wrong.

Thoughts?
<?php

session_start(); 

if (@$_SESSION['auth'] != "yes")                   

{

header("Location: default.php");

exit();

}

ini_set('display_errors', 1);  error_reporting(E_ALL);


include ("../carter.inc");



$cxn = mysqli_connect($host,$user,$password,$database)

or die ("couldn't connect to server");

     function jpgResizeFrom( $filename, $width, $height, $newFilePath, $quality=75 ) { 
	 $width = 160;  // pixels
					$height = 100;   // pixels 
					$newFilePath = 'thumbs';
					$imageFolder = '../Photos';
          if ( file_exists( $filename ) && !is_dir( $filename ) ) { 
               // Get current dimensions and calculate the best size
               list($widthOrig, $heightOrig) = getimagesize($filename);
     
               if ( $heightOrig > 0 ) {
                    
                    $ratioOrig = $widthOrig/$heightOrig;
          
                    if ( ($width/$height) > $ratioOrig)
                         $width = $height * $ratioOrig;
                    else
                         $height = $width / $ratioOrig;
          
          
                    // Resample the original image
                    //
                    $image_p = imagecreatetruecolor($width, $height);
                    $image = imagecreatefromjpeg($filename);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
          
          
                    // Output to a file and clear memory of the old images
                    //
                    imagejpeg($image_p, $newFilePath, $quality);
                    imagedestroy($image_p);
                    imagedestroy($image);
     
               } 

          } // if file_exists
     }


require_once('header.php');



?>

	

		<table border="0" cellspacing="0" cellpadding="0" width=100%>

		<tr>

		<td>

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		<td>

			<table border="0" cellspacing="0" cellpadding="0" width=100%>

			<tr>

			<td class="TitleText">

			<b>Photo List</b>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td class="MainText">

			<P>

			Just sit back and watch the magical transformation happen!

			<P>

			<?php include ("help.php"); ?>

			</td>

			</tr>

			<tr>

			<td>

			&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td>

			<HR>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td align="center">

				<table width=100% border="0">

				<tr>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				<td align="center">

				
					<table>
					<tr>
					<td>
					<?php
					$width = 160;  // pixels
					$height = 100;   // pixels 
					$newFilePath = 'thumbs';
					$imageFolder = '../Photos';
					 //$fileParts = pathinfo($query_row['url'] );
					  //$filename  = $fileParts['filename'];
					  //$extension = strtolower( $fileParts['extension'] );
					  $origName  = "../Photos/Casey Full Body color.jpg";
					  $newName   = "thumbs/Casey Full Body color.jpg"; 
					   jpgResizeFrom( $origName, $width, $height, $newName );
					echo "<a href='./$origName'><img src='$newName' /></a>";

						 ?>
					 </td>
					 </tr>
					 </table>
				 </td>
				 </tr>
					</table>&nbsp;<BR>

				

				</td>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				</tr>

				</table>

			</td>

			</tr>

			</table>

		</td>

		

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		</tr>

		</table>

Open in new window

0
brucegust
Asked:
brucegust
  • 4
  • 4
1 Solution
 
chingmdCommented:
I suggest that you use a full path or variablize the path.    Assuming that you are running under apache, it will not cd to the directory of the php location to run.

0
 
brucegustPHP DeveloperAuthor Commented:
OK!

I'm not getting the error any more, but there isn't any image in the new directory (thumbs).

What am I missing?
<?php

session_start(); 

if (@$_SESSION['auth'] != "yes")                   

{

header("Location: default.php");

exit();

}

ini_set('display_errors', 1);  error_reporting(E_ALL);


include ("../carter.inc");



$cxn = mysqli_connect($host,$user,$password,$database)

or die ("couldn't connect to server");

     function jpgResizeFrom( $filename, $width, $height, $newFilePath, $quality=75 ) { 
	 $width = 160;  // pixels
					$height = 100;   // pixels 
					$newFilePath = 'http://www.countryshowdown.com/adm/thumbs';
					$imageFolder = '../Photos';
          if ( file_exists( $filename ) && !is_dir( $filename ) ) { 
               // Get current dimensions and calculate the best size
               list($widthOrig, $heightOrig) = getimagesize($filename);
     
               if ( $heightOrig > 0 ) {
                    
                    $ratioOrig = $widthOrig/$heightOrig;
          
                    if ( ($width/$height) > $ratioOrig)
                         $width = $height * $ratioOrig;
                    else
                         $height = $width / $ratioOrig;
          
          
                    // Resample the original image
                    //
                    $image_p = imagecreatetruecolor($width, $height);
                    $image = imagecreatefromjpeg($filename);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
          
          
                    // Output to a file and clear memory of the old images
                    //
                    imagejpeg($image_p, $newFilePath, $quality);
                    imagedestroy($image_p);
                    imagedestroy($image);
     
               } 

          } // if file_exists
     }


require_once('header.php');



?>

	

		<table border="0" cellspacing="0" cellpadding="0" width=100%>

		<tr>

		<td>

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		<td>

			<table border="0" cellspacing="0" cellpadding="0" width=100%>

			<tr>

			<td class="TitleText">

			<b>Photo List</b>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td class="MainText">

			<P>

			Just sit back and watch the magical transformation happen!

			<P>

			<?php include ("help.php"); ?>

			</td>

			</tr>

			<tr>

			<td>

			&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td>

			<HR>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td align="center">

				<table width=100% border="0">

				<tr>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				<td align="center">

				
					<table>
					<tr>
					<td>
					<?php
					$width = 160;  // pixels
					$height = 100;   // pixels 
					$newFilePath = 'http://www.countryshowdown.com/adm/thumbs';
					$imageFolder = '../Photos';
					 //$fileParts = pathinfo($query_row['url'] );
					  //$filename  = $fileParts['filename'];
					  //$extension = strtolower( $fileParts['extension'] );
					  $origName  = "../Photos/Casey Full Body color.jpg";
					  $newName   = "http://www.countryshowdown.com/adm/thumbs/Casey Full Body color.jpg"; 
					   jpgResizeFrom( $origName, $width, $height, $newName );
					echo "<a href='./$origName'><img src='$newName' /></a>";

						 ?>
					 </td>
					 </tr>
					 </table>
				 </td>
				 </tr>
					</table>&nbsp;<BR>

				

				</td>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				</tr>

				</table>

			</td>

			</tr>

			</table>

		</td>

		

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		</tr>

		</table>

Open in new window

0
 
Lukasz ChmielewskiCommented:
I wonder if that is related to path style... Try to do this like that (line 178,179)

$origName  = "..//Photos//Casey Full Body color.jpg";
$newName   = "thumbs//Casey Full Body color.jpg";

Might be as well the spaces in the filename.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
chingmdCommented:
In the resizejpgfrom function you want the local path name of the file.  

/var/www/adm/thumbs

Assuming you are using the /var/www at the doc root.

In the link generation, you are OK with using http, or relative location.

The function is actually accessing the file system to create the thumbnail.

0
 
brucegustPHP DeveloperAuthor Commented:
OK, guys, I went back to a similar script but I'm running into the same problem.

This works! Everything is working the way that it should, but the thumbnail is not being saved into the directory which is freakin' me out when you look at the source code, you'll see "http://www.countryshowdown.com/thumbs/charlie_mccoy.jpg" but there's nothing in the thumbs directory. So, I don't even know where this image is coming from.

Mind you the thumbnail itself is great, but I can't see how and or where it's being stored. Again, nothing in the thumbs directory.

What am I missing?
0
 
brucegustPHP DeveloperAuthor Commented:
Here's the code that's workin', it's just not saving the new thumbnaill in the thumbs directory.
<?php



session_start(); 

if (@$_SESSION['auth'] != "yes")                   

{

header("Location: default.php");

exit();

}



include ("../carter.inc");



$cxn = mysqli_connect($host,$user,$password,$database)

or die ("couldn't connect to server");

     function jpgResizeFrom( $filename, $width, $height, $newFilePath, $quality=75 ) { 
          if ( file_exists( $filename ) && !is_dir( $filename ) ) { 
               // Get current dimensions and calculate the best size
               list($widthOrig, $heightOrig) = getimagesize($filename);
     
               if ( $heightOrig > 0 ) {
                    
                    $ratioOrig = $widthOrig/$heightOrig;
          
                    if ( ($width/$height) > $ratioOrig)
                         $width = $height * $ratioOrig;
                    else
                         $height = $width / $ratioOrig;
          
          
                    // Resample the original image
                    //
                    $image_p = imagecreatetruecolor($width, $height);
                    $image = imagecreatefromjpeg($filename);
                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
          
          
                    // Output to a file and clear memory of the old images
                    //
                    imagejpeg($image_p, $newFilePath, $quality);
                    //imagedestroy($image_p);
                    //imagedestroy($image);
     
               } 

          } // if file_exists
     }


require_once('header.php');



?>

	

		<table border="0" cellspacing="0" cellpadding="0" width=100%>

		<tr>

		<td>

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		<td>

			<table border="0" cellspacing="0" cellpadding="0" width=100%>

			<tr>

			<td class="TitleText">

			<b>Photo List</b>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td class="MainText">

			<P>

			Just sit back and watch the magical transformation happen!

			<P>

			<?php include ("help.php"); ?>

			</td>

			</tr>

			<tr>

			<td>

			&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td>

			<HR>

			</td>

			</tr>

			<tr>

			<td>&nbsp;<BR>

			</td>

			</tr>

			<tr>

			<td align="center">

				<table width=100% border="0">

				<tr>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				<td align="center">

				

					<?php

					$width = 160;  // pixels
					$height = 100;   // pixels 
					$newFilePath = '../thumbs/';
					$imageFolder = '../Photos';

					$querystate = "select * from photos where id = '135'";

					$resultstate = mysqli_query($cxn, $querystate)

					or die ("Couldn't execute query.");

					$query_row = mysqli_fetch_assoc($resultstate);
					extract($query_row);
					 $fileParts = pathinfo( $query_row['url'] );
					  $filename  = $fileParts['filename'];
					  echo $filename;
					  $extension = strtolower( $fileParts['extension'] );
					  $origName  = "$imageFolder/$filename.$extension";
					  $newName   = "$newFilePath/$filename.$extension"; 
					  if ( $extension == "jpg" || $extension == "jpeg" ) {
						   jpgResizeFrom( $origName, $width, $height, $newName );
						   echo "<a href='./$origName'><img src='$newName' /></a>";
					  } 

					 ?>
					</table>&nbsp;<BR>

				

				</td>

				<td>

				<IMG SRC="../Images/spacer.gif" width="10" height="10">

				</td>

				</tr>

				</table>

			</td>

			</tr>

			</table>

		</td>

		

		<td>

		<IMG SRC="../Images/spacer.gif" width="10" height="10">

		</td>

		</tr>

		</table>

Open in new window

0
 
chingmdCommented:
So, if I'm reading correctly, what's happening is that the the link is serving data, but when you look where you think the data is coming from, it's empty.

At this point it's no longer a php question.   There are many ways to configure apache to pull data from different locations.   (again assuming that you are running apache.)

search your config files for a thumbs alias.


0
 
brucegustPHP DeveloperAuthor Commented:
So, in other words, the file is there somewhere on the server. It's just not where I'm looking?
0
 
chingmdCommented:
yes.   If you are using apache as the http server, and you have access to the httpd.conf file, look for an alias of thumbs or a rewrite rule.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now