图像插入不起作用


image insertion is not working

当|I插入图像时,它显示错误

无效的偏移

这是我的控制器。

我已经从我项目的另一个页面复制了它,它在那里工作——但在新页面上,它显示了错误。

  $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;

您已经设置了一些图像缩略图

$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');

那么这些设置是如何将config添加到库中的。


添加此

$this->load->library('image_lib', $configThumb); # configuration variable

读取此

图像操作类