Hello All,

I am rather confused. I am trying to create a photo gallery using the script attached below but when I run the file it returns the following warnings.

I don't understand the directory that it is looking for, as the one that it wants is available.

In the config.inc.php the directory fot the photos is defined as
$images_dir = 'photos';

This file itself seats within the directory so i don't understand why it can not find it.

Could somebody please explain part or all of the message below.

Any help would be really great.

Thanks
Neil

Warning: copy(photos/10.jpg): failed to open stream: No such file or directory in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 51

Warning: getimagesize(photos/10.jpg): failed to open stream: No such file or directory in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 54

Warning: Division by zero in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 62

Warning: imagecreatefromjpeg(photos/10.jpg): failed to open stream: No such file or directory in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 71

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 84

<?php
	include("config.inc.php");
	include 'design.inc.php';
	// initialization
	$result_final = "";
	$counter = 0;

// List of our known photo types
$known_photo_types = array( 
					'image/pjpeg' => 'jpg',
					'image/jpeg' => 'jpg',
					'image/gif' => 'gif',
					'image/bmp' => 'bmp',
					'image/x-png' => 'png'
				);

// GD Function List
$gd_function_suffix = array( 
					'image/pjpeg' => 'JPEG',
					'image/jpeg' => 'JPEG',
					'image/gif' => 'GIF',
					'image/bmp' => 'WBMP',
					'image/x-png' => 'PNG'
				);

// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];

// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];

while( $counter <= count($photos_uploaded) )
{
	if($photos_uploaded['size'][$counter] > 0)
	{
		if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
		{
			$result_final .= "File ".($counter+1)." is not a photo<br />";
		}
		else
		{
			mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
			$new_id = mysql_insert_id();
			$filetype = $photos_uploaded['type'][$counter];
			$extention = $known_photo_types[$filetype];
			$filename = $new_id.".".$extention;

			mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

			// Store the orignal file
			copy($photos_uploaded['tmp_name'] [$counter], $images_dir."/".$filename); // [[U]B[U]](THIS IS LINE 51)[/[/U]B][/U]

			// Let's get the Thumbnail size
			$size = GetImageSize( $images_dir."/".$filename );// [[U]B[U]](THIS IS LINE 54)[/[/U]B][/U]
			if($size[0] > $size[1])
			{
				$thumbnail_width = 100;
				$thumbnail_height = (int)(100 * $size[1] / $size[0]);
			}
			else
			{
				$thumbnail_width = (int)(100 * $size[0] / $size[1]); //[[U]B[U]](THIS IS LINE 62)[/[/U]B][/U]
				$thumbnail_height = 100;
			}

			$function_suffix = $gd_function_suffix[$filetype]; 
$function_to_read = 'ImageCreateFrom' . $function_suffix; 
$function_to_write = 'Image' . $function_suffix; 

// Read the source file 
$source_handle = $function_to_read($images_dir . '/' . $filename); //[[U]B[U]](THIS IS LINE 71)[/[/U]B][/U]

if ($source_handle) { 
 // Let's create a blank image for the thumbnail 
 $destination_handle = 
   ImageCreateTrueColor($thumbnail_width, $thumbnail_height); 

 // Now we resize it 
 ImageCopyResampled($destination_handle, $source_handle, 
   0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]); 
} 

// Let's save the thumbnail 
$function_to_write($destination_handle, $images_dir . '/tb_' . $filename); //[[U]B[U]](THIS IS LINE 84)[/[/U]B][/U]

			//
			$result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
		}
	}
$counter++;
}

// Print Result
echo <<<__HTML_END

<html>
<head>
	<title>Photos uploaded</title>
</head>
<body>
	$result_final
</body>
</html>

__HTML_END;
?>

    In the config.inc.php the directory fot the photos is defined as
    $images_dir = 'photos';

    This file itself seats within the directory...

    What do you mean by "seats within the directory"? If you mean the script is in the "photos" directory, then just use './' . $filename. If not, then you need to adjust the path to get to that directory.

      Hi

      When I say it seats with the directory I mean that the path is
      sportsmatesreunited.co.uk/photos/upload.php.

      Could you adit the following line of code so that i can see exactly what you mean please.

      //this is line 51
      copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);

      Many thanks

        copy($photos_uploaded['tmp_name'][$counter], "./".$filename);

        Should do it. ("./" refers to the current directory.)

          Ok I've made the changes as you have discribed but I am still getting the following message.

          I am hoping the one leads on from another.

          What should I do?

          Warning: copy(./16.jpg): failed to open stream: Permission denied in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 51

          Warning: getimagesize(./16.jpg): failed to open stream: No such file or directory in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 54

          Warning: Division by zero in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 62

          Warning: imagecreatefromjpeg(./16.jpg): failed to open stream: No such file or directory in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 71

          Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 84

            You'll need to set the correct permissions. I recommend a tutorial, such as this one (Part 2).

            They probably do lead one from the other.

              Hi Thanks for that, it was pretty useful.

              I can see how to change the permissions on a known file but the script is creating temporary files and folders. How do I set the permissions on these.

              I've attached the edited code but I am getting the following error still.

              Do you have any suggestion?

              Really appriciate your help.

              Thanks
              Neil

              Warning: copy(./25.jpg): failed to open stream: Permission denied in /home/users/uks53122/html/sportsmatesreunited.co.uk/photos/upload.php on line 65

              <?php
              
              $fr = fopen("./", 'r');
              if(!$fr) {
              	/* Must be 0444 (octal), NOT just 444 */
              	if(!chmod("./", 0777)) {
              		echo "Error -- couldn't open upload.php for reading!";
              		exit;
              	} else {
              		$fr = fopen("./", 'r');
              	}
              }
              $myvalue = fgets($fr, 1024);
              fclose($fr);
              
              include("config.inc.php");
              include ('design.inc.php');
              // initialization
              $result_final = "";
              $counter = 0;
              
              // List of our known photo types
              $known_photo_types = array( 
              					'image/pjpeg' => 'jpg',
              					'image/jpeg' => 'jpg',
              					'image/gif' => 'gif',
              					'image/bmp' => 'bmp',
              					'image/x-png' => 'png'
              				);
              
              // GD Function List
              $gd_function_suffix = array( 
              					'image/pjpeg' => 'JPEG',
              					'image/jpeg' => 'JPEG',
              					'image/gif' => 'GIF',
              					'image/bmp' => 'WBMP',
              					'image/x-png' => 'PNG'
              				);
              
              // Fetch the photo array sent by preupload.php
              $photos_uploaded = $_FILES['photo_filename'];
              
              // Fetch the photo caption array
              $photo_caption = $_POST['photo_caption'];
              
              while( $counter <= count($photos_uploaded) )
              {
              	if($photos_uploaded['size'][$counter] > 0)
              	{
              		if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
              		{
              			$result_final .= "File ".($counter+1)." is not a photo<br />";
              		}
              		else
              		{
              			mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
              			$new_id = mysql_insert_id();
              			$filetype = $photos_uploaded['type'][$counter];
              			$extention = $known_photo_types[$filetype];
              			$filename = $new_id.".".$extention;
              
              			mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
              
              			// Store the orignal file
              			copy($photos_uploaded['tmp_name'][$counter], "./".$filename); //THIS IS LINE 65
              
              
              			// Let's get the Thumbnail size
              			$size = GetImageSize( "./".$filename );
              			if($size[0] > $size[1])
              			{
              				$thumbnail_width = 100;
              				$thumbnail_height = (int)(100 * $size[1] / $size[0]);
              			}
              			else
              			{
              				$thumbnail_width = (int)(100 * $size[0] / $size[1]);
              				$thumbnail_height = 100;
              			}
              
              			$function_suffix = $gd_function_suffix[$filetype]; 
              $function_to_read = 'ImageCreateFrom' . $function_suffix; 
              $function_to_write = 'Image' . $function_suffix; 
              
              // Read the source file 
              $source_handle = $function_to_read( './' . $filename); 
              
              if ($source_handle) { 
               // Let's create a blank image for the thumbnail 
               $destination_handle = 
                 ImageCreateTrueColor($thumbnail_width, $thumbnail_height); 
              
               // Now we resize it 
               ImageCopyResampled($destination_handle, $source_handle, 
                 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]); 
              } 
              
              // Let's save the thumbnail 
              $function_to_write($destination_handle, './tb_' . $filename);
              
              			//
              
              			$result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
              		}
              	}
              $counter++;
              }
              
              // Print Result
              echo <<<__HTML_END
              
              <html>
              <head>
              	<title>Photos uploaded</title>
              </head>
              <body>
              	$result_final
              </body>
              </html>
              
              __HTML_END;
              ?>
                Write a Reply...