1

ユーザーが画像をアップロードできる管理パネルを作成する宝石に関するプロジェクトに取り組んでいますが、画像のサイズを変更しようとしていますが、アップロードしている特定のディレクトリに黒い出力が表示されます。これが私のコードです。

 $target_path = SITE_ROOT .DS. $this->upload_dir .DS. $this->filename;

      // Make sure a file doesn't already exist in the target location
      if(file_exists($target_path)) {
        $this->errors[] = "The file {$this->filename} already exists.";
        return false;
      }
      // i am trying to resize the image
     if( copy ($this->temp_path,$this->filename) or die     ("Could not copy")){
     $imagefile=$this->filename;
   list($width, $height) = getimagesize($this->filename);
   $image_p = imagecreatetruecolor($this->new_width,$this->new_height);
   if ($this->type =='jpg') 
   {
       $img = imagecreatefromgif($imagefile);
       imagecopyresampled($image_p, $img, 0, 0, 0, 0, $this->new_width,$this->new_height, $width, $height);
       imagegif($image_p,$target_path);
   }
   else{ echo 'something went wrongs';}
   }
        // Attempt to move the file 
        if(move_uploaded_file($this->temp_path, $target_path)) {
        // Success
            // Save a corresponding entry to the database
            if($this->create()) {
                // We are done with temp_path, the file isn't there anymore
                unset($this->temp_path);
                return true;
            }
        } else {
            // File was not moved.
        $this->errors[] = "The file upload failed, possibly due to incorrect permissions on the upload folder.";
        return false;
        } 
4

1 に答える 1