Hi everybody i`m trying to upload an image with codeigniter on my localhost(WAMP) but two problems appeared:
You must specify a source image in your preferences.
Your server does not support the GD function required to process this type of image.
I tried what not to fix it but no result
Here it is my code :
开发者_开发技巧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();
}
}
}
I'm guessing here, but I think the problem is that you're calling $this->image_lib->resize()
twice, but the second one's configuration is cleared after you run the first one - so it's not finding the file, and that's triggering the second error. "this type of image" is probably a NULL value or something. You're doing error checking only on the second call as well, so the first one may very well be working fine.
Try this change and see if it helps:
$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();
}
Another way you can do it:
$this->load->library('image_lib');
$this->image_lib->initialize($config);
$success = $this->image_lib->resize();
if ( ! $success)
{
echo $this->image_lib->display_errors();
}
Either way, and even if this is not your only issue, you should only call resize()
once.
In php.ini you have to change this line upload_max_filesize = 2MB
精彩评论