2012-01-30 3 views
0

非常に簡単な操作をしようとしていますが、動作させることができません。それは価値があるため、私は現在MAMPのマシンでテストしていますが、ステージングサーバー(GoDaddy GridHost)から同じ結果を得ています。CodeIgniter 2 image_lib-> resize()エラー - 空白のページをレンダリングし、エラーメッセージを返しません。

  1. はフォームから、ユーザが指定した画像をアップロードする:

    は、ここで私が何をしたいのです。

  2. アップロードした画像のサムネイルを作成します。

あり、私の例では、いくつかの余分なデータベース・コードがあるが、もし(!の$ this - > image_lib->サイズを変更する())コールでスクリプト「エラー」。ただし、アプリケーション全体が終了し、空白のページが表示されます。コードは実際にif {}ブロックに入ることはありません。

function _upload_image(&$location, &$image = NULL) 
{ 
    // Configure the initial full-sized image upload 
    $upload_config = array(
     'upload_path' => "./uploads/users/{$this->viewer->id}/locations/{$location->id}/", 
     'allowed_types' => 'jpg|jpeg|gif|bmp|png', 
     'max_size' => 8192 // 8mb 
    ); 

    $this->load->library('upload', $upload_config); 

    // Upload failed 
    if(! $this->upload->do_upload('image')) 
    { 
     $this->errors = strip_tags($this->upload->display_errors()); 
     return FALSE; 
    } 

    // Get the uploaded file's metadata 
    $data = $this->upload->data(); 

    // Change permissions of the uploaded file so that the image library can copy and resize it 
    if(is_file($config['upload_path'] . $data['file_name'])) 
    { 
     chmod($config['upload_path'] . $data['file_name'], 0777); 
    } 

    // If no existing image object was passed to this function, we are creating a brand new image 
    if(is_null($image)) 
    { 
     $image = new Image(); 
     $thumbnail = new Thumbnail(); 
    } 
    else 
    { 
     $thumbnail = $image->thumbnail->get(); // Get the existing thumbnail 
    } 

    // Set the image object fields to save to the db 
    $image->name = $data['file_name']; 
    $image->mime_type = $data['file_type']; 
    $image->extension = $data['file_ext']; 
    $image->file_path = $data['file_path']; 
    $image->full_path = $data['full_path']; 
    $image->size = $data['file_size']; 
    $image->width = $data['image_width']; 
    $image->height = $data['image_height']; 

    // Failed to save the image to the db 
    if(! $image->save()) 
    { 
     $this->errors = array_merge($this->errors, array($image->error->string)); 
     return FALSE; 
    } 

    // Failed to save the location/image relationship in the db 
    if(! $location->save($image)) 
    { 
     $this->errors = array_merge($this->errors, array($location->error->string)); 
     return FALSE; 
    } 

    // Configure options for the thumbnail 
    $thumb_config = array(
     'image_library' => 'GD2', 
     'source_image' => "./uploads/users/{$this->viewer->id}/locations/{$location->id}/{$image->name}", 
     'create_thumb' => TRUE, 
     'width' => 400, 
     'height' => 300 
    ); 

    $this->load->library('image_lib'); 
    $this->image_lib->initialize($thumb_config); 

    // Failed to create the image thumbnail 
    if(! $this->image_lib->resize()) 
    { 
     $this->errors = array_merge($this->errors, array($this->image_lib->display_errors())); 
     return FALSE; 
    } 

    // Set the thumbnail object fields to save to the db 
    $thumbnail->name = $data['raw_name'] . '_thumb' . $data['file_ext']; 
    $thumbnail->file_path = $image->file_path; 
    $thumbnail->full_path = $image->file_path . $thumbnail->name; 

    // Failed to save the thumbnail to the db 
    if(! $thumbnail->save()) 
    { 
     $this->errors = array_merge($this->errors, array($thumbnail->error->string)); 
     return FALSE; 
    } 

    // Failed to save the image/thumbnail relationship in the db 
    if(! $image->save($thumbnail)) 
    { 
     $this->errors = array_merge($this->errors, array($image->error->string)); 
     return FALSE; 
    } 

    // Everything worked 
    return TRUE; 
} 

データベースとの対話は、私は完全性のために含まDataMapperのORMによって処理されるが、私はそれが必ずしも、この問題に関連している感じることはありません。機能は明らかに呼び出しで失敗:

if(! $this->image_lib->resize()) 
+0

同じ事が私に起こりますので、$ CI-> image_lib-> clear();を入れます。 image_lib-> resize()の後 –

答えて

0

あなたはindex.phpのブートストラップでアプリケーション環境を設定することがありますか?まだ開発していない場合は、テスト/プロダクションに設定されている場合には表示されないようにエラーを表示することができます。

define('ENVIRONMENT', 'development'); 

問題を診断できない場合は、MAMPの[サーバー]タブで[PHP]をクリックし、[ログを表示]をクリックします。これにより、PHPエラーログファイルが開き、何が起きているのかを知ることができます。

+0

はい、私の環境定数は、dev、staging、およびproductionに対して正しく設定されています。 –

+0

PHPエラーログはあなたに手がかりを与えますか? – Adam

関連する問題