⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How can I change upload path according to the date?



jpmayoral
  • profile picture
  • Member

Posted 13 September 2012 - 16:14 PM

Hi everybody! I wann change upload path with before_callback

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...

victor
  • profile picture
  • Member

Posted 13 September 2012 - 20:10 PM

[s]Hi!
I do not get what you want.[/s]

victor
  • profile picture
  • Member

Posted 13 September 2012 - 20:15 PM

Hi, Jpmayoral!

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?

jpmayoral
  • profile picture
  • Member

Posted 14 September 2012 - 02:20 AM

Hi victor thanks for your reply! But it didn't work for me... My question is if I can use 'callback_before_upload' function in order to change the upload path according to a specific date... Thanksss!

victor
  • profile picture
  • Member

Posted 14 September 2012 - 08:42 AM

Why do you want use exactly callback function for this? Does this path based on date from calendar(datepicker) or not?

Juampi Mayoral
  • profile picture
  • Member

Posted 14 September 2012 - 13:03 PM

I wanna create the folder according to some date selected by user in datepicker... for example:

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...

midnigther
  • profile picture
  • Member

Posted 14 September 2012 - 14:00 PM

Use post function to retrieve the date.

$this->input->post ('date');

victor
  • profile picture
  • Member

Posted 14 September 2012 - 14:02 PM

I ask you later. I working now) sorry, but I have solution)

victor
  • profile picture
  • Member

Posted 14 September 2012 - 14:09 PM

midnigther answered yuor question.

Juampi Mayoral
  • profile picture
  • Member

Posted 14 September 2012 - 14:32 PM

Thanks for your reply midnigther! but I still have doubt about how can I change the upload path according to the date... thankssss

victor
  • profile picture
  • Member

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;
}
}
}
}

victor
  • profile picture
  • Member

Posted 16 September 2012 - 18:05 PM

$this->input->post('date_create') - your date field.

Juampi Mayoral
  • profile picture
  • Member

Posted 17 September 2012 - 16:15 PM

Victor thanks a lot! It's worked wonderful! I was making a mistake with the path cause I wrote base_url() and my real path is "/var/www/application_name/assets/uploads"... that was the reason... :D Problem Solved!

Kun Hernowo Putra
  • profile picture
  • Member

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