[eluser]pisces77[/eluser]
Hi thanks in advance, i'm building image gallery i'm not saving file extension to database and in view i was just using filename than concatenate extension .jpg but now problem is if user upload .png than i run into problem...
also thumbnail generated by image_lib attach word _thumb to original file name here again i have to code..what i have to code ?..what if it save file with original file name but in different folder so i just change the path and it would work....
some one suggested me to check if file exist than get extension of that file i don't know i did't like that option..
currently
1 - my controller simply upload files i'm using uploadify...and model insert record in database without file extension just filename.
2 - controller get all photos from model and i pass that object to view and loop through all files...
sorry for the long explanation i'm newbie may be some one can point there you are doing wrong...do this way...
CONTROLLER
Code:
function uploadify()
{
//Decode JSON returned by /js/uploadify/upload.php
$file = $this->input->post('filearray');
$data['json'] = json_decode($file);
/*thumnail creation*/
$this->load->library('image_lib');
$path = 'D:/wamp/www/xcroo/uploads/';
$config['image_library'] = 'gd2';
$config['source_image'] = $path.$data['json']->file_name;
$config['new_image'] = $path;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 80;
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
//large thumbnail
$config['new_image'] = $path.'thumb_large/';
$config['width'] = 600;
$config['height'] = 500;
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize())
{
// echo $this->image_lib->display_errors();
}
/*end thumbnail creation*/
$member = $this->members_model->get_members_info($this->session->userdata('sess_member_id'));
$file_name = substr($data['json']->file_name, 0, strrpos($data['json']->file_name, '.'));
$data['photo_id'] =$this->members_model->add_photos($data['json']->file_name);
$data['file_name']=$file_name;
//print_r($data['json'])."<br/>";
//print $data['json']->file_path;
$this->load->view('upload/uploadify',$data);
}
MODAL add photo
Code:
public function add_photos($photo_name){
$data= array('photo_name'=>$photo_name,
'member_id'=>$this->session->userdata('sess_member_id')
);
$this->db->insert('photos',$data);
$photo_id = $this->db->insert_id();
return $photo_id;
}
controller index function to get all photos
Code:
public function index(){
$data['member'] = $this->members_model->get_members_info($this->session->userdata('sess_member_id'));
$data['query'] = $this->members_model->get_photos();
$this->load->view('members/photos',$data);
}
view for all photos
Code:
<?php
foreach($query->result() as $rows):?>
<div class="labeled_image photo_image">
<a >config->item('base_url').'photos/photo/'.$rows->photo_id; ?>"><img class="box_user_image">config->item('base_url').'uploads/thumb_medium/'.$rows->photo_name.'_thumb.jpg'; ?>" alt="" width="100" height="80"/></a>
</div>
i appreciate reading my long boring problem thank you so much for the help in advance...i want to learn how modal should be used some one suggest me don't use uri segment in modal control it through controller...etc