0

私は現在、Web サイトのメディア ライブラリに取り組んでいます。機能の 1 つは、ユーザーがアップロードした画像の切り抜きバージョンを作成できることです。

ただし、私の問題はこれです。画像をトリミングしようとすると、次のエラーが表示されます。

The path to the image is not correct.

ここに私のコードがあります、

$config['image_library'] = 'gd2';
    $config['source_image'] = "/media/images/products/".$this->data['image'];
    //die($config['source_image']);
    $config['maintain_ratio'] = FALSE;
    $config['x_axis'] = $this->input->post('x');
    $config['y_axis'] = $this->input->post('y');
    $config['width'] = $this->input->post('w');
    $config['height'] = $this->input->post('h');
    $config['dynamic_output'] = FALSE;
    $config['create_thumb'] = TRUE;
    $this->load->library('image_lib', $config);

    if(!$this->image_lib->crop()) {
        if($this->input->post('isAjax') == "1") {
            echo json_encode($this->image_lib->display_errors());
        } else {
            $this->data['image_error'] = $this->image_lib->display_errors();
            $this->template->build('/admin/media/crop', $this->data);
        }       
    } else {
        $filename = base_url()."media/images/products/".$this->data['image'];
        $extension_pos = strrpos($filename, '.'); // find position of the last dot, so where the extension starts
        $thumb = substr($filename, 0, $extension_pos) . '_thumb' . substr($filename, $extension_pos);
        if($this->input->post('isAjax') == 1) {
            echo json_encode($success = array('message' => 'Image Cropped'));
        } else {
            $this->data['success'] = "Image Cropped";
            $this->template->build('/admin/media/crop', $this->data);
        }   
    }

だから私は次のように変更$config['source_image']しますが、

$config['source_image'] = "./media/images/products/".$this->data['image'];

ただし、このメッセージが表示されるだけです。

Your server does not support the GD function required to process this type of image.

私は根本的に間違ったことをしていますか?私は単純な .png をトリミングしようとしているだけで、ファイルは確かにサーバーに存在し、間違いなく GD2 がインストールされています。

4

1 に答える 1

0

これはファイル パスの問題である可能性が最も高いです (CI は、正確で関連性のあるエラー メッセージについて非常に優れています)。これを解決するために私が取るステップは次のとおりです。

  1. var_dump(file_exists($config['source_image'])PHPがファイルを見つけるかどうかを確認します。ここで「本当の」反応にショックを受けるでしょう。
  2. ファイルシステムで大文字と小文字が区別される場合は、それが問題ではないことを確認してください
  3. インクルード パスを確認します (CI がここまで到達すれば、通常のインクルードは正常に機能していると思います...)
  4. $_SERVER['DOCUMENT_ROOT']コメンターが示唆するように 、アンチステップですが、使用しないでください。FC_PATH(または他の CI 定義の定数) は、必要な基本パスを取得する必要があります。

楽しい狩り。

于 2012-02-02T06:15:54.623 に答える