[solved] help me find a bug with file uploading - El Forum - 04-26-2011
[eluser]SPeed_FANat1c[/eluser]
Hi,
Code: if(!$this->upload->do_upload())
{
//echo $config['upload_path'];
$error = $this->upload->display_errors();
echo $error.':err'; //pagal galune .err javasctriptas atskirs kad cia klaida
}
else
{
$data = $this->upload->data();
$this->load->model('Image_model','image');
if($data['image_width'] > 700)
{
$task = $this->image->image_resize_for_gallery('./uploads/gallery/'.$this->input->post('album_folder').'/'.$data['file_name']);
if($task != 'ok')
{
echo $task.':err'; //pagal galune .err javasctriptas atskirs kad cia klaida
}
}
if($this->image->gallery_thumb($this->input->post('album_folder'),$data['file_name']))
{
$this->image->gallery_enter_image($data['file_name'],$this->input->post('album_folder'));
echo $data['file_name'];
}
else
{
echo 'Nepavyko įkelt mažos nuotraukytes:err';
}
}
This is code fragment from file uploading function. This works well when image_width is not > 700. But when it is > 700, then the thumbnail is not created.
Now here you can see gallery_thumb function in Image_model:
Code: function gallery_thumb($album_folder,$image_name)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/gallery/'.$album_folder.'/'.$image_name;
$config['new_image'] = './uploads/gallery/'.$album_folder.'/thumbs';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
/// $this->image_lib->display_errors();
log_message('error', $this->image_lib->display_errors());
return FALSE;
}
else return TRUE;
}
gallery_thumb is returning TRUE, I assume this because this
Code: if($this->image->gallery_thumb($this->input->post('album_folder'),$data['file_name']))
{
$this->image->gallery_enter_image($data['file_name'],$this->input->post('album_folder'));
echo $data['file_name'];
}
echoes $data['file_name'];
Where the problem could be that it does not create thumbnail when image_with is > 700 ?
[solved] help me find a bug with file uploading - El Forum - 04-26-2011
[eluser]toopay[/eluser]
did your ' if($data['image_width'] > 700)' statement fired?
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]SPeed_FANat1c[/eluser]
[quote author="toopay" date="1303866860"]did your ' if($data['image_width'] > 700)' statement fired?[/quote]
yeah, I made an echo inside the { } and it was echoed.
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]astrofire[/eluser]
I m wondering why you differentiate between <700 and >700 width pics.
Why not pushing all images through the same thumbnail procedure?
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]toopay[/eluser]
Looks lke to me, that your execution break somewhere in 'image_resize_for_gallery' function on 'Image_model'.
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]SPeed_FANat1c[/eluser]
Quote:I m wondering why you differentiate between <700 and >700 width pics.
Why not pushing all images through the same thumbnail procedure?
There are two reasons:
1. If the picture is more than 700, then I resize and it is smaller, loads faster on a webpage.
2. I use galleria plugin http://galleria.aino.se/ and if the picture is bigger then it shows it wrong (not rezised) and on IE throws javascript errors.
If the picture width is less than 700 I don't need to execute resizing script.
Ok, I post an image model code:
Code: <?php
class Image_model extends CI_Model
{
function Image_model()
{
parent::__construct();
}
/*
* Naujienoms ir info puslapiams
*/
//parametro pvz: './uploads/info_pages/file.jpg'
function image_resize($source_image)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $source_image;
$config['maintain_ratio'] = TRUE;
$config['width'] = 534;
$config['height'] = 700;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
return $this->image_lib->display_errors();
}
else return 'ok';
}
/*
* galerijoje ikeliant paveiksliukus padaro ir mazus paveiksliukus
* sekmes atveju grazina true, nesekmes false
*/
//parametro pvz - /path/to/image/mypic.jpg';
function gallery_thumb($album_folder,$image_name)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/gallery/'.$album_folder.'/'.$image_name;
$config['new_image'] = './uploads/gallery/'.$album_folder.'/thumbs';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
/// $this->image_lib->display_errors();
log_message('error', $this->image_lib->display_errors());
return FALSE;
}
else return TRUE;
}
//galerijai - ivedam uploadinta nuotrauka i duombaze
function gallery_enter_image($filename,$album_id)
{
$data = array(
'file_name' => $filename,
'album_id' => $album_id
);
$query = $this->db->insert('gallery_photos',$data);
if(!$query)
{
//kad nebutu nesamoniu, istrinam ir failus is serverio
unlink('./uploads/gallery/'.$album_id.'/'.$filename);
$image_thumb = substr_replace($filename, '_thumb', strlen($filename)-4, 0); //strlen($filename)-4 cia suzinom pozicija, kurioj vietoj idet ta _thumb, .jpg
unlink('./uploads/gallery/'.$album_id.'/thumbs/'.$image_thumb);
log_message('error', 'image_model, gallery_enter_image() Nepavyko ivesti galerijos paveiksliuko i duomenu baze');
}
}
/**
* galerijai reik sumazint nuotraukas, nes dideliu siaip ar taip nerodom, taigi taupys srauta, greiciau kraus, o be to kai dideles tai klaidas meta ir pirmaji karta negraziai rodo ant chrome
*
* parametro pvz: './uploads/gallery/10/file.jpg'
*/
function image_resize_for_gallery($source_image)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $source_image;
$config['maintain_ratio'] = TRUE;
$config['width'] = 534;
$config['height'] = 700;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
return $this->image_lib->display_errors();
}
else return 'ok';
}
}
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]toopay[/eluser]
Have you try to put this flag
Code: $this->image_lib->clear();
after execute resizing process?
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]SPeed_FANat1c[/eluser]
[quote author="toopay" date="1303919791"]Have you try to put this flag
Code: $this->image_lib->clear();
after execute resizing process?[/quote]
Added.
Code: function image_resize_for_gallery($source_image)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $source_image;
$config['maintain_ratio'] = TRUE;
$config['width'] = 700;
$config['height'] = 700;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
$this->image_lib->clear();
return $this->image_lib->display_errors();
}
else
{
$this->image_lib->clear();
return 'ok';
}
}
Now from this part
Code: if($this->image->gallery_thumb($this->input->post('album_folder'),$data['file_name']))
{
$this->image->gallery_enter_image($data['file_name'],$this->input->post('album_folder'));
echo $data['file_name'];
}
else
{
echo 'Nepavyko įkelt mažos nuotraukytes:err';
}
I get 'Nepavyko įkelt mažos nuotraukytes:err'
so at least it says that it not created thumbnail.
So I made a model function to echo a message why it does not create a thumbnail:
Code: function gallery_thumb($album_folder,$image_name)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/gallery/'.$album_folder.'/'.$image_name;
$config['new_image'] = './uploads/gallery/'.$album_folder.'/thumbs';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize())
{
/// $this->image_lib->display_errors();
log_message('error', $this->image_lib->display_errors());
echo $this->image_lib->display_errors(); //test
$this->image_lib->clear();
return FALSE;
}
else
{
$this->image_lib->clear();
return TRUE;
}
}
And I get this:
<p>Your server does not support the GD function required to process this type of image.</p>
I am testing only with .jpg images. I remind you - If the image is not resized, then thumbnail is created. But when the resizing is executed, then I get this error. So it means that it does not understand the image type or change it after resizing..
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]toopay[/eluser]
Have you try to include 'create_thumb' on resize config at 'image_resize_for_gallery'?
[solved] help me find a bug with file uploading - El Forum - 04-27-2011
[eluser]SPeed_FANat1c[/eluser]
[quote author="toopay" date="1303922646"]Have you try to include 'create_thumb' on resize config at 'image_resize_for_gallery'?[/quote]
I think there is no point to do that, because create_thumb is already in gallery_thumb function.
Also
Quote:For practical purposes there is no difference between creating a copy and creating a thumbnail except a thumb will have the thumbnail marker as part of the name (ie, mypic_thumb.jpg).
so it just changes a file name..
|