Ok i have this code which puts a watermark on images when their uploaded but i would say 1 out of every 10 pics is broken the other 9 work fine what do you think i could be?

PHP Code:
if ( $_FILES['fupload']['type'] == "image/pjpeg" ) { $extension=".jpg"; }
if ( 
$_FILES['fupload']['type'] == "image/jpeg" ) { $extension=".jpg"; }
  
$number rand();
  
$filename="$Sess_UserName"."$number"."$extension";
  
$targetfile="members/"."$filename";
  
$uploaded $_FILES['fupload']['tmp_name'];
  
$fullpath '/home/hotfaceo/public_html/'.$targetfile;
            
//watermark code

// Set a maximum height and width
  
$width 400;
  
$height 400;
    
// Content type..didn't work when i had the content type set
//header('Content-type: image/jpeg');
// Get new dimensions

  
list($width_orig$height_orig) = getimagesize($uploaded);
  if (
$width_orig >= 400 || $height_orig >= 400
    {
          if (
$width && ($width_orig $height_orig)) 
        {
        
$width = ($height $height_orig) * $width_orig;
        } 
        else 
       {
        
$height = ($width $width_orig) * $height_orig;
      }} 
        else 
            {
        
$width $width_orig;
        
$height $height_orig;
       }
// Resample
  
$image_p imagecreatetruecolor($width$height);
  
$image imagecreatefromjpeg($uploaded);
  
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);
  
$picture $image_p;
  
$logo "images/watermark.jpg";
  
$logosize getimagesize(rtrim($logo));
  
$logox $logosize[0];
  
$logoy $logosize[1];
  
$pictureim $picture;
  
$logoim imagecreatefromjpeg($logo);
  
imagecopy$pictureim$logoimimagesx$pictureim ) - imagesx$logoim ) - 5imagesy$pictureim ) - imagesy$logoim ) - 500imagesx$logoim ), imagesy$logoim ) );
                
// Output
  
imagejpeg($pictureim$fullpath75);
  
imagedestroy($image);
  
imagedestroy($image_p);
            
#########################################
            #         End Watermark Code            #
            #########################################