当我插入图像时,它显示错误
无效偏移
这是我的控制器。
我已经从我项目中的其他页面复制了它并且它正在那里工作 - 但是在新页面上显示错误。
$config['upload_path'] = './assets/upload/'; /* NB! create this dir! */
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '5000';
$config['max_height'] = '5000';
/* Load the upload library */
$this->load->library('upload', $config);
/* Create the config for image library */
/* (pretty self-explanatory) */
$configThumb = array();
$configThumb['image_library'] = 'gd2';
$configThumb['source_image'] = '';
$configThumb['create_thumb'] = TRUE;
$configThumb['maintain_ratio'] = TRUE;
/* Set the height and width or thumbs */
/* Do not worry - CI is pretty smart in resizing */
/* It will create the largest thumb that can fit in those dimensions */
/* Thumbs will be saved in same upload dir but with a _thumb suffix */
/* e.g. 'image.jpg' thumb would be called 'image_thumb.jpg' */
$configThumb['width'] = 140;
$configThumb['height'] = 210;
/* Load the image library */
$this->load->library('image_lib');
$file=array();
$file_thumb=array();
/* We have 5 files to upload
* If you want more - change the 6 below as needed
*/
for($i = 1; $i < 3; $i++) {
/* Handle the file upload */
$upload = $this->upload->do_upload('image'.$i);
/* File failed to upload - continue */
if($upload === FALSE) continue;
/* Get the data about the file */
$data = $this->upload->data();
$file[$i] = $data['file_name'];
$file_thumb[$i] = $data['raw_name'].'_thumb'.$data['file_ext'];
$uploadedFiles[$i] = $data;
/* If the file is an image - create a thumbnail */
if($data['is_image'] == 1) {
$configThumb['source_image'] = $data['full_path'];
$this->image_lib->initialize($configThumb);
$this->image_lib->resize();
}
}
///=============upload end here==================////
echo $file['1'];
exit;
答案 0 :(得分:0)
您已设置了一些图像拇指
$configThumb = array();
$configThumb['image_library'] = 'gd2';
$configThumb['source_image'] = '';
$configThumb['create_thumb'] = TRUE;
$configThumb['maintain_ratio'] = TRUE;
$configThumb['width'] = 140;
$configThumb['height'] = 210;
好的谢谢。并加载库$this->load->library('image_lib');
所以这个设置如何配置到库。
添加此内容
$this->load->library('image_lib', $configThumb); # configuration variable
阅读本文