Iamge upload and gd2 library

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fonz
Forum Newbie
Posts: 1
Joined: Wed Mar 03, 2004 5:12 am
Location: Newcastle - UK

Iamge upload and gd2 library

Post by Fonz »

Please help, my script outputs the following errors when i run it:
Warning: move_uploaded_file(home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/images/test/9.jpg): failed to open stream: No such file or directory in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 599

Warning: move_uploaded_file(): Unable to move '/tmp/phpKgtDdp' to 'home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/images/test/9.jpg' in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 599

Warning: getimagesize(): Unable to access home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/images/test/9.jpg in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 602

Warning: getimagesize(home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/images/test/9.jpg): failed to open stream: No such file or directory in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 602

Warning: Division by zero in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 614

Fatal error: Call to undefined function: imagecreatefrom() in /home/httpd/vhosts/northumbriastgeorges.com/httpdocs/admin/gallery.php on line 623
The main error i'm concerned with is the fact that the files do not seem to be uploaded the rest i'll figure out once i've got that working, my script is as follows:

Code: Select all

function upload_pic()
  {
    //fetch image array created by add pic function
    $photos_uploaded = $_FILES['photo_filename'];
    
    //fetch image caption array
    $photo_captions = $_POST['photo_captions'];
    
    //create array of mime types in order to check validity of pictures
    $photo_types = array(  
    'image/pjpeg' => 'jpg',
    'image/jpeg' => 'jpg',
    'image/gif' => 'gif',
    'image/bmp' => 'bmp',
    'image/x-png' => 'png'
    );
    

    while($counter <= count($photos_uploaded))
      {
        if($photos_uploaded['size'][$counter] > 0)
          {
            if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
             $result_final .= 'File ' . ($counter + 1) .
           ' is not a photo<br />';
             }
        else
          {
     $query = "INSERT into pictures values ('','0','$gallery_id','$photo_captions[$counter]')";
     mysql_query($query) or die(mysql_error());

$new_id = mysql_insert_id(); // New Id generated

// Get the filetype of the uploaded file
$filetype = $photos_uploaded['type'][$counter];  

// Get the extension for the new name
$extension = $photo_types[$filetype];  

// Generate a new name
$filename = "$new_id.$extension";  
$folder = $_GET['folder'];
$img = 'home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/images/'.$folder;
$imgpath = $img.'/';
$thumb = 'home/httpd/vhosts/northumbriastgeorges.com/httpdocs/gallery/thumbnails/'.$folder;
$thumbpath = $thumb.'/';

// let’s update the filename now
mysql_query("UPDATE pictures SET path='$filename' WHERE id='$new_id'");

move_uploaded_file($photos_uploaded['tmp_name'][$counter], $imgpath . $filename);

//get image size in preparation for automatic thumbnails
$size = GetImageSize($imgpath. $filename);

// Wide Image
if($size[0] > $size[1])
{  
$thumbnail_width = 100;  
$thumbnail_height = (int)(100 * $size[1] / $size[0]);  
}  

// Tall Image
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($imgpath . $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, $thumbpath . $filename);

echo "<table width="100%" border="0">
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td bgcolor="#003366"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">
                    Your photos have been uploaded:</font></strong></td>
              </tr>
             <tr>
               <td bgcolor="#CFD8F5">To view the new photos, please click <a href="gallery.php?action=edit&id=$id&folder=$folder">here</a></td>
                </tr></table>";
    
    
    
    }
   }
}
}
anyone got any ideas? - thanks

Fonz

***EDIT***

Sorry missed a couple of lines there :oops:
Post Reply