Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 问题必须在首选项中指定源图像_Codeigniter - Fatal编程技术网

Codeigniter 问题必须在首选项中指定源图像

Codeigniter 问题必须在首选项中指定源图像,codeigniter,Codeigniter,大家好,我正试图用codeigniter在本地主机(WAMP)上上传一张图片,但出现了两个问题: 必须在首选项中指定源图像 您的服务器不支持处理此类映像所需的GD功能 我试过什么办法不去解决它,但没有结果 这是我的代码: class Upload_mod extends CI_Model{ var $gallery_path; var $gallery_path_url; function index(){ parent::__construct(); $this

大家好,我正试图用codeigniter在本地主机(WAMP)上上传一张图片,但出现了两个问题:

必须在首选项中指定源图像

您的服务器不支持处理此类映像所需的GD功能

我试过什么办法不去解决它,但没有结果

这是我的代码:

class Upload_mod extends CI_Model{

  var $gallery_path;
  var $gallery_path_url;

  function index(){
    parent::__construct();
    $this->gallery_path = realpath(APPPATH . '../uploads');
    $this->gallery_path_url = base_url().'uploads/';
  }

  function do_upload() {
    $config = array(
      'allowed_types' => 'jpg|jpeg|gif|png',
      'upload_path'   => $this->gallery_path);

    $this->load->library('upload');
    $this->upload->initialize($config);
    $this->upload->do_upload();
    $image_data = $this->upload->data();
    print_r($image_data);

    if ( ! $this->upload->do_upload())
    {
      $error = array('error' => $this->upload->display_errors());
      gd_info();
      echo $error;
    }    

    $config['source_image'] = $image_data['full_path'];
    $config['new_image'] = $this->gallery_path . '/thumbs';
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 75;
    $config['height'] = 50;

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

    if ( ! $this->image_lib->resize())
    {
      echo $this->image_lib->display_errors();
    }

  }
}

我在这里猜测,但我认为问题在于您调用了两次
$this->image_lib->resize()
,但是在运行第一个之后,第二个的配置被清除了-因此它找不到文件,这触发了第二个错误。“这种类型的图像”可能是空值或其他值。您只在第二次调用中执行错误检查,因此第一次调用可能运行良好

尝试此更改,看看是否有帮助:

$this->load->library('image_lib');
$this->image_lib->initialize($config);
// $this->image_lib->resize(); Remove this call to resize()

if ( ! $this->image_lib->resize())
{
  echo $this->image_lib->display_errors();
}
另一种方法是:

$this->load->library('image_lib');
$this->image_lib->initialize($config);
$success = $this->image_lib->resize();

if ( ! $success)
{
  echo $this->image_lib->display_errors();
}
无论哪种方式,即使这不是您的唯一问题,您也应该只调用一次php.ini中的
resize()

你必须换这条线
上载\u max\u filesize=2MB

不幸的是没有任何更改。
var\u dump($image\u data['full\u path'])
返回什么?如果它似乎是一个正确的路径,请尝试将
is_file()
环绕在它周围,看看会发生什么。如果你得到任何有趣的结果,把它们加到你的问题中。