나는 아주 간단한 작업을 시도하고 있지만 제대로 작동하지 않습니다. 가치가있는 부분에 대해서는 현재 MAMP dev machine에서 테스트 중이지만 준비 서버 (GoDaddy GridHost)에서 동일한 결과를 얻습니다.CodeIgniter 2 image_lib-> resize() 오류 - 빈 페이지를 렌더링하고 오류 메시지를 반환하지 않습니다.
- 폼에서 사용자가 지정한 이미지를 업로드 :
여기에 내가하고 싶은거야.
- 업로드 한 이미지의 미리보기 이미지를 만듭니다.
내 예제에서 몇 가지 추가 데이터베이스 코드가 있지만, 에서 스크립트 "오류"경우 호출 (! $ 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())
같은 일이 일어나서 $ CI-> image_lib-> clear(); image_lib-> resize() 후 –