Suddenly faced with a problem of photos not uploading

I have a personal site with a gallery which I built using the code in the sitepoint article, Build an Automated PHP Gallery system in minutes by Mayank Gandhi. My gallery had been working very well. I have a gallery page with different categories of photos with their thumbnails. I also managed to build an admin system whereby I could upload, edit, delete categories and photos. It had been functioning well. I had uploaded quite a few photos to my gallery. I have also edited many of them from time to time.

I am suddenly faced with a problem. I went to the admin section of my gallery page after many months. I tried uploading a few photos but they are not getting uploaded at all. I had downloaded a few photos from my camera which I tried uploading to my gallery page.

Whenever I tried uploading a jpeg image, I kept getting te following message.

Warning: copy(/photos/171.jpg) [function.copy]: failed to open stream: No such file or directory in /home/jppp/public_html/upload.php on line 48
Warning: getimagesize(/photos/171.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/jppp/public_html/upload.php on line 52
Warning: Division by zero in /home/jppp/public_html/upload.php on line 72
Warning: imagecreatefromjpeg(/photos/171.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/jppp/public_html/upload.php on line 87
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/jppp/public_html/upload.php on line 98
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jppp/public_html/upload.php on line 99
File 1 Added Successfully!

It says File 1 Added Successfully but there is only the x mark where the photo should be. The caption is getting uploaded and I am getting the next and previous links to work but the actual photo is not there. Why has this started happening suddenly?

I must mention that I have a new pc now where I have downloaded wamp again.

Then I tried uploading a gif image but I got the message saying that the file is not a photo. I have used the code provided by Mayank Gandhi and created all the admin pages after a lot of discussion in this same forum. My code had been working well earlier. I presume it cannot be anything wrong with my code since I had got everything working earlier. Even now, I am able to edit photos and their categories. It is only uploading which is causing the problem.

There is also a slight problem while deleting a photo.
I went to the section for editing photos and edited a photo. I got the message,

Warning: unlink(/photos/171.jpg) [function.unlink]: No such file or directory in /home/jppp/public_html/edit_photo.php on line 100

Warning: unlink(/photos/tb_171.jpg) [function.unlink]: No such file or directory in /home/jppp/public_html/edit_photo.php on line 101
Process completed!

Now my photo, 171.jpg is getting deleted and I do not have a problem. But why am I getting a message like this?

I tried to delete a category. I again got the message,

Warning: unlink(/photos/170.png) [function.unlink]: No such file or directory in /home/jppp/public_html/administration.php on line 113

Warning: unlink(/photos/169.png) [function.unlink]: No such file or directory in /home/jppp/public_html/administration.php on line 113
Process completed!

Here again, my category did get deleted. So, what I wanted is indeed happening, but again, why am I getting this error message?
When I tried adding a category, it did get added.

Why am I having these problems which I did not face earlier? What could have gone wrong?

I wondered whether gd was not enabled since I had recently installed wamp in my new pc, but I checked for phpinfo() and found the following:

gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.37
WBMP Support enabled
XBM Support enabled
Directive Local Value Master Value
gd.jpeg_ignore_warning 0 0

I am giving below the codes for my upload function.

 
<?php
include("config.inc.php");
 
// initialization
$result_final = "";
$counter = 0;
// List of our known photo types
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/bmp' => 'bmp',
'image/x-png' => 'png');
 
// GD Function Suffix List
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG');
// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];
$photoFileName= $_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);
// Let's get the original image size
 
$size = GetImageSize( $images_dir."/".$filename );
// First Create Thumbnail!
// Thumbnail Settings
        $Config_tbwidth_wide = 100; // width of wide image
        $Config_tbheight_wide = 75; // height of wide image
        $Config_tbwidth_tall = 100; // width of tall image
        $Config_tbheight_tall = 75; // height of tall image
// The Code
        if($size[0] > $size[1]){
            $thumbnail_width = $Config_tbwidth_wide;
            $thumbnail_height = (int)($Config_tbwidth_wide * $size[1] / $size[0]);
            if($thumbnail_height > $Config_tbheight_wide){
                $thumbnail_height = $Config_tbheight_wide;
                $thumbnail_width = (int)($Config_tbheight_wide * $size[0] / $size[1]);
            }
        }else{
            $thumbnail_width = (int)($Config_tbheight_tall * $size[0] / $size[1]);
            $thumbnail_height = $Config_tbheight_tall;
            if($thumbnail_width > $Config_tbwidth_tall){
                $thumbnail_width = $Config_tbwidth_tall;
                $thumbnail_height = (int)($Config_tbwidth_tall * $size[1] / $size[0]);
            }
        }
// Build Thumbnail with GD 2.x.x, you can use the other described methods too
$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 );
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, 100 );
ImageDestroy($destination_handle );
// .................................................................................
// Lets resize the image if its width is greater than 500 pixels
// Resized image settings
if ($size[0] > '500'){
        $Config_width_wide = 500; // width of wide image
        $Config_height_wide = 475; // height of wide image
        $Config_width_tall = 475; // width of tall image
        $Config_height_tall = 500; // height of tall image
// The Code
        if($size[0] > $size[1]){
            $image_width = $Config_width_wide;
            $image_height = (int)($Config_width_wide * $size[1] / $size[0]);
            if($image_height > $Config_height_wide){
                $image_height = $Config_height_wide;
                $image_width = (int)($Config_height_wide * $size[0] / $size[1]);
            }
        }else{
            $image_width = (int)($Config_height_tall * $size[0] / $size[1]);
            $image_height = $Config_height_tall;
            if($image_width > $Config_width_tall){
                $image_width = $Config_width_tall;
                $image_height = (int)($Config_width_tall * $size[1] / $size[0]);
            }
        }
// Build image with GD 2.x.x, you can use the other described methods too
$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 );
if($source_handle){
// Let's create a blank image for the image
$destination_handle = ImageCreateTrueColor ( $image_width, $image_height );
// Now we resize it
ImageCopyResampled( $destination_handle, $source_handle, 0, 0, 0, 0, $image_width, $image_height, $size[0], $size[1] );
}
// Let's save the image
$function_to_write( $destination_handle, $images_dir."/".$filename, 90 );
ImageDestroy($destination_handle );
}
$result_final .= "<img src='".$images_dir. "/tb_".$filename."' /><br />File ".($counter+1)." Added Successfully!<br /><br />";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
<html>
<head>
        <title>Photos uploaded</title>
</head>
<body>
$result_final<br>
<a href="preupload.php">Upload more photos</a>|<a href="index.html">Home</a>|<a href="admin.php">Back to administration page</a><br>
</body>
</html>
__HTML_END;
?>
 
 

I changed the path in my config file and now it works.
The path in my config file said,
$images_dir = ‘/photos’;
I changed it to $images_dir = ‘photos’; and now it is working.

Thanks for the help given by all of you. Coastweb, I should have read your thread more thoroughy earlier. I really need to learn more about the absolute and relative paths.
Thanks once again.

Thanks.

The other thing to check is there any room in the server/folder for any more images.

Will this apply even if my hosting plan says unlimited space and unlimited bandwidth?

I believe the path is incorrect.

But, Coastweb, I have not made any changes to my code. I was able to upload photos earlier with the same code.

I believe the path is incorrect.

You have “/photos/171.jpg” when it is most likely supposed to be “photos/171.jpg”

The last one equates to “/home/jppp/public_html/photos/171.jpg”
the first one is trying to access “/photos” from the root directory which you should not have access to for security reasons.

Looking at the code it appears you might have $images_dir set incorrectly.
make it “photos” (relative path) or “/home/jppp/public_html/photos” (absolute path).

File 1 Added Successfully!
Is not realy telling you anything as it is not checking the file is on the server only the output of the code.

I would echo out some of your path variables to see you see getting what you expect and check the folder to see if the image is there somewhere.

The other thing to check is there any room in the server/folder for any more images.