How can I change upload path according to the date?
- Single Page
Posted 13 September 2012 - 16:14 PM
I have this:
$crud->set_field_upload('pago_archivo_comprobante', 'assets/uploads/files');
$crud->callback_before_upload(array($this,'verificar_path_callback'));
function verificar_path_callback($files_to_upload,$field_info){
if(is_dir($field_info->upload_path)){
return true;
}
else{
$path = base_url().'assets/uploads/2012';
mkdir($path,0777);
return true;
}
}
How can i set the new path? Thanks...
Posted 13 September 2012 - 20:10 PM
I do not get what you want.[/s]
Posted 13 September 2012 - 20:15 PM
Maybe it's:
function example()
{
...
$path = 'assets/uploads/files/'.date('d-m-Y',time());
$crud->set_field_upload('pago_archivo_comprobante', $this->verificar_path_callback($path));
....
}
function verificar_path_callback($path)
{
if(is_dir($path))
{
return $path;
}
else
{
$path = base_url().'assets/uploads/'.date('d-m-Y',time();
if(mkdir($path,0777))
{
return $path;
}
else
{
log_message('error','Problem with creating folders. Path:' . $path);
exit;
}
}
NOTE:
But you have to modify a function that will to create the folder if you creating a record, or use the old folder, if you editing a record, because will be created a new folder each time you open this page.
helped you?
Posted 14 September 2012 - 02:20 AM
Posted 14 September 2012 - 08:42 AM
Posted 14 September 2012 - 13:03 PM
If the user choose 10/07/2012 I'll have to create a folder in a path like this: assets/uploads/2012/July...
According to groceryCRUD docs I saw the callback_before_upload and I thought I'd change the folder path with this but... I tried to with no success...
I tried your code but it didn't work...
Posted 14 September 2012 - 14:00 PM
$this->input->post ('date');
Posted 14 September 2012 - 14:02 PM
Posted 14 September 2012 - 14:09 PM
Posted 14 September 2012 - 14:32 PM
Posted 16 September 2012 - 17:49 PM
function example()
{
...
$crud->set_field_upload('pago_archivo_comprobante', $this->verificar_path_callback());
....
}
function verificar_path_callback()
{
if($this->input->post('date_create'))
{
$path = base_url().'assets/uploads/'.$this->input->post('date_create');
if(is_dir($path))
{
return $path;
}
else
{
$path = base_url().'assets/uploads/'.$this->input->post('date_create')
if(mkdir($path,0777))
{
return $path;
}
else
{
log_message('error','Problem with creating folders. Path:' . $path);
exit;
}
}
}
}
Posted 16 September 2012 - 18:05 PM
Posted 17 September 2012 - 16:15 PM
Posted 07 February 2014 - 06:11 AM
public function lookbook_image(){
if($this->session->userdata('logged_in')){
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->view('administrator', $data);
}
else{
redirect('login','refresh');
}
$crud = new grocery_CRUD();
$crud->set_table('lookbook_image');
$crud->set_subject('Image Look Book');
$crud->required_fields('image');
$crud->columns('lookbookCategoryId','imageTitle','imageDescription','image','active');
$crud->display_as('sortOrder', 'Sort Order');
$crud->display_as('lookbookCategoryId', 'Look Book Category');
$crud->display_as('imageTitle', 'Image Title');
$crud->display_as('imageDescription', 'Image Description');
$crud->field_type('dateAdd', 'hidden');
$crud->field_type('dateEdit', 'hidden');
$crud->set_field_upload('image','assets/uploads/files');
$crud->set_relation('active','aktivasi','active');
$crud->set_relation('lookbookCategoryId', 'lookbook_category', 'lookbookTitle');
$crud->set_field_upload('image', $this->mkdir_upload());
$crud->unset_export();
$crud->unset_print();
$output = $crud->render();
$this->lookbook_image_crud($output);
}
public function lookbook_image_crud($output = NULL){
$this->load->view('lookbook_image.php',$output);
}
public function mkdir_upload(){
if($this->input->post('lookbookCategoryId')){
$path = base_url(). '../images/lookbook/' . $this->input->post('lookbookCategoryId');
if(is_dir($path)){
return $path;
}
else{
$path = base_url() . '../images/lookbook/' . $this->input->post('lookbookCategoryId');
if(mkdir($path,0777)){
return $path;
}
else{
log_message('error','Problem with creating folders. Path:' . $path);
exit;
}
}
}
}
I have a problem with loading upload not working
