Image resizing [ The path to the image is not correct.] - El Forum - 10-23-2009
[eluser]Unknown[/eluser]
Code: <?php
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$num=7; //for user_id
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite']=TRUE;
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='avatar_'.$num;
$iconfig['image_library'] = 'GD2'; //i also wrote GD/gd2
$iconfig['source_image']='home/username/public_html/images/'.$config['file_name'].'.jpg';
$iconfig['create_thumb'] = TRUE;
//$iconfig['maintain_ratio'] = TRUE;
$iconfig['width'] = 70;
$iconfig['height'] = 90;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
$this->load->library('image_lib');
$this->image_lib->initialize($iconfig);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
}
}
}
?>
Image is uploaded but it is not resized.
I tested this is Localhost the path i gave something like C:/Xampp/htdocs....
Now i am getting this error
Quote:The path to the image is not correct.
Your server does not support the GD function required to process this type of image.
Your file was successfully uploaded!
file_name: scoefield.jpg
file_type: image/jpeg
file_path: /home/username/public_html/images/
full_path: /home/username/public_html/images/scoefield.jpg
raw_name: scoefield
orig_name: scoefield.jpg
file_ext: .jpg
file_size: 8.64
is_image: 1
image_width: 200
image_height: 258
image_type: jpeg
image_size_str: width="200" height="258"
Image resizing [ The path to the image is not correct.] - El Forum - 10-23-2009
[eluser]BrianDHall[/eluser]
Well, two things - the path isn't right, and it doesn't seem your server supports the GD function which is the PHP extension module that handles image resizing - so you have two issues going on.
The first change is try using existing path data for your resize function as provided by the image upload class, as such:
Code: function do_upload
{
$num=7; //for user_id
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite']=TRUE;
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='avatar_'.$num;
$iconfig['image_library'] = 'GD2'; //i also wrote GD/gd2
$iconfig['create_thumb'] = TRUE;
//$iconfig['maintain_ratio'] = TRUE;
$iconfig['width'] = 70;
$iconfig['height'] = 90;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
$this->load->library('image_lib');
$iconfig['source_image']=$data['upload_data']['full_path'];
$this->image_lib->initialize($iconfig);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
}
}
Image resizing [ The path to the image is not correct.] - El Forum - 10-23-2009
[eluser]clip[/eluser]
It is quite possible your getting the GD Error because it is not finding an image. Doing as BH has proposed should solve your problem.
|