Reputation: 329
I have to function where one function is call_back function. Now i want to get value (value from "$iamge_location" variable) into another function. i am trying to return the value from callback function and print it into another function from where callback function is called. but i did not get the value plz help..
Here is My controller code:
function RoomImageAdd(){
$this->form_validation->set_rules('roomImage', 'Upload Image', 'callback_upload_Image');
$roomid = $this->input->post('roomid');
if ($this->form_validation->run() == FALSE) {
$this->addRoomImage($roomid);
}
else {
echo $image_location;
}
}
function upload_Image(){
if(!empty($_FILES['roomImage']['name']))
{
$filename = date('YmdHis');
$config['upload_path'] = 'assets/img/upload/rooms/';
$config['allowed_types'] = 'jpg|jpeg';
$config['file_name'] = $filename;
$config['max_size'] = '2000';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$this->upload->initialize($config);
if (!$this->upload->do_upload('roomImage'))
{
$this->form_validation->set_message('upload_Image', $this->upload->display_errors('',''));
return FALSE;
}
else
{
$image_data = $this->upload->data();
$image_location = 'assets/img/upload/rooms/'.$image_data['file_name'];
$config['image_library'] = 'gd2';
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = $image_data['file_path'].'room_thumb/';
$config['maintain_ratio'] = FALSE;
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_thumb';
$config['width'] = 280;
$config['height'] = 280;
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()) {
$error = array('error' => $this->image_lib->display_errors());
} else {
$this->image_lib->resize();
}
return $image_location;
}
}
else{
$this->form_validation->set_message('upload_Image', "Unexpected Error! No File Selected!");
return FALSE;
}
}
Upvotes: 1
Views: 159
Reputation: 5258
In your controller you should be able to add a field variable image_location
which you can set in your update_Image
function.
Change
return $image_location;
to
$this->image_location = $image_location;
return true; // because a boolean is expected off of a validation callback
Now you can use $this->image_location
to access the location in your RoomImageAdd
method.
Upvotes: 1