它给出了空白屏幕:/它上传第一张图片,没关系。而不是它调用_create_thumbnail,它在“$ this-> image_lib-> resize()”行显示空白屏幕:/
任何想法可能是什么问题?
谢谢!
/ **
* ================================================= =================
* 上传照片
*
* Thumb = 210px - 160px
*原始= 500px - 385px
*
* /
function img_upload()
{
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$config['width'] = 500;
$config['height'] = 385;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
$fInfo = $this->upload->data();
$this->_create_thumbnail($fInfo['file_name']);
$data['uploadInfo'] = $fInfo;
$data['thumbnail_name'] = $fInfo['raw_name'] . '_thumb' . $fInfo['file_ext'];
// set view
$this->load->view('upload_success', $data);
}
}
function _create_thumbnail($fileName)
{
$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/' . $fileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 210;
$config['height'] = 160;
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}
答案 0 :(得分:1)
在这里查看大括号:
if(!$this->upload->do_upload()) echo $this->upload->display_errors();
else {
看起来你正在混合语法风格。
答案 1 :(得分:0)
尝试删除$fileName
:
而不是:$config['source_image'] = 'uploads/' . $fileName;
使用此:$config['source_image'] = 'uploads/'
答案 2 :(得分:0)
试试这个
function _create_thumbnail($fileName)
{
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/' . $fileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 210;
$config['height'] = 160;
$config['new_image'] = './uploads/'.$fileName;
$this->image_lib->initialize($config);
if(!$this->image_lib->resize()) echo
$this->image_lib->display_errors();
}