My thumbnails are getting black whenever caught from an external site location
My php made thumbnails are turning into all black squares when I pull the images from sites addresses such as :http://grupointelligenza.com.br/images/stories/google.jpg .
  <p> Here is the php at the upload site: </P>


    if(isset($_POST['submit'])){
       
        $image = new Image();
        $image->caption = $_POST['caption'];
        $image->user_id = $_POST['user_id'];
        $image->attach_file($_FILES['file_upload']);
        
        if ($image->save()){
            
            $image->createThumb($_FILES['file_upload'],115,115);
            $session->message("Imagem enviada com sucesso.");
            header("Location:list_images.php");
            die;
            
        }else{
            
            $session->message(implode("<br>",$image->error));
            
        }
    }

And here it is the code of the image class I'm using to process it:

    <?php
    
    include 'C:\wamp\www\OOP_Teste\includes\initialize.php';
    
    class Image extends Database_obj {
        
       protected static $table_name = "images";
       protected static $attributes = array('id', 'filename', 'type', 'size', 'caption', 'user_id');
       public $id;
       public $filename;
       public $type;
       public $size;
       public $caption;
       public $user_id;
       
       protected $upload_errors = array(
              UPLOAD_ERR_OK            =>'Upload realizado.',
              UPLOAD_ERR_INI_SIZE      =>'Tamanho máximo superado no php.',
              UPLOAD_ERR_FORM_SIZE     =>'Tamanho máximo superado no html.',
              UPLOAD_ERR_PARTIAL       =>'Upload parcial.',     
              UPLOAD_ERR_NO_FILE       =>'Nenhum arquivo selecionado.',
              UPLOAD_ERR_NO_TMP_DIR    =>'Nenhum diretório temporário no servidor.',
              UPLOAD_ERR_CANT_WRITE    =>'Diretório não editável.',
              UPLOAD_ERR_EXTENSION     =>'Extensão do arquivo problemática.'
         );
    
       public static $max_file_size = 2000000;
       
       private   $temp_path;
       protected $thumb_dir     = 'thumbs';
       protected $upload_dir    = 'imagens';
       public    $error         = array();
    
       
       public function directory(){
           
           return $directory = $this->upload_dir.DS.$this->filename;
           
       }
       
       public function size(){
           
           if ($this->size > 1024){
               return round($this->size/1024)."kB";
           }elseif ($this->size > 1048576){
               return round($this->size/1048576)."MB";
           }else{
               return $this->size."bytes";
           }
               
           
       }
       
       private function _ext(){
           
            return strrchr($this->filename, ".");
        }
       
        public function comments (){
            
            return Comment::find_comments($this->id);
            
        }   
          
          public function createThumb($file, $new_w = 115, $new_h = 115){
            
    //NAME MANAGEMENT:
           $name = $file['name'];
           $nameParts = explode('.', $name);
           $cleanName = cleanFileName($name);
           $cleanNameParts = explode('.', $cleanName);
                       
            if (preg_match('/jpg|jpeg/',$nameParts[1])){
                
                    $src_img = imagecreatefromjpeg("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" . $file['name']);
            }
            
            if (preg_match('/png/',$nameParts[1])){
                
                    $src_img = imagecreatefrompng("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" .$file['name']);
            }
    
            $old_x = imageSX($src_img);
            $old_y = imageSY($src_img);
            
            if ($old_x > $old_y) {
                
                    $thumb_w = $new_w;
                    $thumb_h = $old_y*($new_h/$old_x);
            }
            
            if ($old_x < $old_y) {
                
                    $thumb_w = $old_x*($new_w/$old_y);
                    $thumb_h = $new_h;
            }
            
            if ($old_x == $old_y) {
                
                    $thumb_w = $new_w;
                    $thumb_h = $new_h;
                    
            }
            
            $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
            imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    
                if (preg_match("/png/",$name[1])){
                        imagepng($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.png");
                } elseif (preg_match("/jpg|jpeg/",$name[1])) {
                        imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.jpg");
                } elseif (preg_match("/gif/",$name[1])) {
                        imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.gif");
                }
                
                imagedestroy($dst_img); 
                imagedestroy($src_img);
                        
       }
       
               public function image_path () {
                   
                      return $this->upload_dir.DS.$this->filename;
                      
                    }
                    
                public function thumb_path () {
    
                    $n_ex = explode('.', $this->filename);
    
                    if ($this->type == 'image/jpeg') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.jpg';
                    } elseif ($this->type == 'image/png') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.png';
                    } elseif ($this->type == 'image/gif') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.gif';
                    } else {
                        return false;
                    }
                }     
                                         
               public function remover () {
    
                   if ($this->delete ()) {
                        $target = SITE_ROOT . DS . 'publico' . DS . $this->image_path();
                        $targetThmb = SITE_ROOT . DS . 'publico' . DS . $this->thumb_path();
                           
                        if (unlink($target) && unlink($targetThmb)) {
                            return true;
                        }
                   }
                   
                   return false;
                }
    
              
       public function attach_file ($file) {
           
           if (!$file || empty($file) || !is_array($file)) {
               
               $this->error[] = 'Argumento $file não estabelecido.';
               return false;
               
           } elseif ($file['error'] != 0) {
               
               $this->error = $this->upload_errors[$file['error']];
               return false;
                          
           } else {
           
               $this->temp_path = $file['tmp_name'];
               $this->size      = $file['size']; 
               $this->filename  = basename(cleanFileName($file['name']));
               $this->type      = $file['type'];
               
               
               
               return true;
                          
           }
       }
       
       public function save() {
            
            if (isset($this->id)) {
             
                if($this->update()) {
                    
                    return true;
                    
                }
                
            } else {
                
                if (!empty($this->error)) {return false;}
                
                if (strlen($this->caption) >= 255) {
                    
                    $this->error[] = "Tamanho limite  do subtítulo da imagem é de 255 caractéres.";
                    return false;
                    
                }
                
                if (empty($this->filename) || empty($this->temp_path)) {
                    
                    $this->error[] = "Arquivo não disponível";
                    return false;
                    
                }
                
                $target_root = SITE_ROOT.DS."publico" .DS. $this->upload_dir .DS. $this->filename;
                
                if (file_exists($target_root)) {
                    
                    $this->error[] = "O arquivo '{$this->filename}' já existe.";
                    return false;
                    
                }
                
                if (move_uploaded_file($this->temp_path, $target_root)) {
                    
                    if ($this->create ()) {
                        
                        unset($this->temp_path);
                        return true;
                        
                    }
                    
                } else {
                    
                    $this->error[] = "O arquivo não pode ser movido devido às permissões incorretas em seu diretório destino.";
                    return false;
                    
                }
                
                
                            
            }
            
        }
       
            
    }
    
    ?>



My thumbnails are getting black whenever caught from an external site location
===

My php made thumbnails are turning into all black squares when I pull the images from sites addresses such as :http://grupointelligenza.com.br/images/stories/google.jpg .
  <p> Here is the php at the upload site: </P>


    if(isset($_POST['submit'])){
       
        $image = new Image();
        $image->caption = $_POST['caption'];
        $image->user_id = $_POST['user_id'];
        $image->attach_file($_FILES['file_upload']);
        
        if ($image->save()){
            
            $image->createThumb($_FILES['file_upload'],115,115);
            $session->message("Imagem enviada com sucesso.");
            header("Location:list_images.php");
            die;
            
        }else{
            
            $session->message(implode("<br>",$image->error));
            
        }
    }

And here it is the code of the image class I'm using to process it:

    <?php
    
    include 'C:\wamp\www\OOP_Teste\includes\initialize.php';
    
    class Image extends Database_obj {
        
       protected static $table_name = "images";
       protected static $attributes = array('id', 'filename', 'type', 'size', 'caption', 'user_id');
       public $id;
       public $filename;
       public $type;
       public $size;
       public $caption;
       public $user_id;
       
       protected $upload_errors = array(
              UPLOAD_ERR_OK            =>'Upload realizado.',
              UPLOAD_ERR_INI_SIZE      =>'Tamanho máximo superado no php.',
              UPLOAD_ERR_FORM_SIZE     =>'Tamanho máximo superado no html.',
              UPLOAD_ERR_PARTIAL       =>'Upload parcial.',     
              UPLOAD_ERR_NO_FILE       =>'Nenhum arquivo selecionado.',
              UPLOAD_ERR_NO_TMP_DIR    =>'Nenhum diretório temporário no servidor.',
              UPLOAD_ERR_CANT_WRITE    =>'Diretório não editável.',
              UPLOAD_ERR_EXTENSION     =>'Extensão do arquivo problemática.'
         );
    
       public static $max_file_size = 2000000;
       
       private   $temp_path;
       protected $thumb_dir     = 'thumbs';
       protected $upload_dir    = 'imagens';
       public    $error         = array();
    
       
       public function directory(){
           
           return $directory = $this->upload_dir.DS.$this->filename;
           
       }
       
       public function size(){
           
           if ($this->size > 1024){
               return round($this->size/1024)."kB";
           }elseif ($this->size > 1048576){
               return round($this->size/1048576)."MB";
           }else{
               return $this->size."bytes";
           }
               
           
       }
       
       private function _ext(){
           
            return strrchr($this->filename, ".");
        }
       
        public function comments (){
            
            return Comment::find_comments($this->id);
            
        }   
          
          public function createThumb($file, $new_w = 115, $new_h = 115){
            
    //NAME MANAGEMENT:
           $name = $file['name'];
           $nameParts = explode('.', $name);
           $cleanName = cleanFileName($name);
           $cleanNameParts = explode('.', $cleanName);
                       
            if (preg_match('/jpg|jpeg/',$nameParts[1])){
                
                    $src_img = imagecreatefromjpeg("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" . $file['name']);
            }
            
            if (preg_match('/png/',$nameParts[1])){
                
                    $src_img = imagecreatefrompng("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" .$file['name']);
            }
    
            $old_x = imageSX($src_img);
            $old_y = imageSY($src_img);
            
            if ($old_x > $old_y) {
                
                    $thumb_w = $new_w;
                    $thumb_h = $old_y*($new_h/$old_x);
            }
            
            if ($old_x < $old_y) {
                
                    $thumb_w = $old_x*($new_w/$old_y);
                    $thumb_h = $new_h;
            }
            
            if ($old_x == $old_y) {
                
                    $thumb_w = $new_w;
                    $thumb_h = $new_h;
                    
            }
            
            $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
            imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    
                if (preg_match("/png/",$name[1])){
                        imagepng($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.png");
                } elseif (preg_match("/jpg|jpeg/",$name[1])) {
                        imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.jpg");
                } elseif (preg_match("/gif/",$name[1])) {
                        imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.gif");
                }
                
                imagedestroy($dst_img); 
                imagedestroy($src_img);
                        
       }
       
               public function image_path () {
                   
                      return $this->upload_dir.DS.$this->filename;
                      
                    }
                    
                public function thumb_path () {
    
                    $n_ex = explode('.', $this->filename);
    
                    if ($this->type == 'image/jpeg') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.jpg';
                    } elseif ($this->type == 'image/png') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.png';
                    } elseif ($this->type == 'image/gif') {
                        return $this->upload_dir . DS . $this->thumb_dir . DS . $n_ex[0] . '_thumb.gif';
                    } else {
                        return false;
                    }
                }     
                                         
               public function remover () {
    
                   if ($this->delete ()) {
                        $target = SITE_ROOT . DS . 'publico' . DS . $this->image_path();
                        $targetThmb = SITE_ROOT . DS . 'publico' . DS . $this->thumb_path();
                           
                        if (unlink($target) && unlink($targetThmb)) {
                            return true;
                        }
                   }
                   
                   return false;
                }
    
              
       public function attach_file ($file) {
           
           if (!$file || empty($file) || !is_array($file)) {
               
               $this->error[] = 'Argumento $file não estabelecido.';
               return false;
               
           } elseif ($file['error'] != 0) {
               
               $this->error = $this->upload_errors[$file['error']];
               return false;
                          
           } else {
           
               $this->temp_path = $file['tmp_name'];
               $this->size      = $file['size']; 
               $this->filename  = basename(cleanFileName($file['name']));
               $this->type      = $file['type'];
               
               
               
               return true;
                          
           }
       }
       
       public function save() {
            
            if (isset($this->id)) {
             
                if($this->update()) {
                    
                    return true;
                    
                }
                
            } else {
                
                if (!empty($this->error)) {return false;}
                
                if (strlen($this->caption) >= 255) {
                    
                    $this->error[] = "Tamanho limite  do subtítulo da imagem é de 255 caractéres.";
                    return false;
                    
                }
                
                if (empty($this->filename) || empty($this->temp_path)) {
                    
                    $this->error[] = "Arquivo não disponível";
                    return false;
                    
                }
                
                $target_root = SITE_ROOT.DS."publico" .DS. $this->upload_dir .DS. $this->filename;
                
                if (file_exists($target_root)) {
                    
                    $this->error[] = "O arquivo '{$this->filename}' já existe.";
                    return false;
                    
                }
                
                if (move_uploaded_file($this->temp_path, $target_root)) {
                    
                    if ($this->create ()) {
                        
                        unset($this->temp_path);
                        return true;
                        
                    }
                    
                } else {
                    
                    $this->error[] = "O arquivo não pode ser movido devido às permissões incorretas em seu diretório destino.";
                    return false;
                    
                }
                
                
                            
            }
            
        }
       
            
    }
    
    ?>


