⚠ 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 forum is read-only and soon will be archived. ⚠


How can I change upload path according to the date?

upload files date change path

  • Please log in to reply
13 replies to this topic

#1 Juampi Mayoral

Juampi Mayoral

    Member

  • Members
  • PipPip
  • 12 posts

Posted 13 September 2012 - 04: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...

#2 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 13 September 2012 - 08:10 PM

Hi!
I do not get what you want.


#3 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 13 September 2012 - 08: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?

Edited by victor, 13 September 2012 - 10:01 PM.


#4 Juampi Mayoral

Juampi Mayoral

    Member

  • Members
  • PipPip
  • 12 posts

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!

#5 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

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?

#6 Juampi Mayoral

Juampi Mayoral

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 September 2012 - 01: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...

#7 midnigther

midnigther

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts

Posted 14 September 2012 - 02:00 PM

Use post function to retrieve the date.
$this->input->post ('date');


#8 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 14 September 2012 - 02:02 PM

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

#9 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 14 September 2012 - 02:09 PM

midnigther answered yuor question.

#10 Juampi Mayoral

Juampi Mayoral

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 September 2012 - 02: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

#11 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 16 September 2012 - 05: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;

             }

        }

    }

}



#12 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 16 September 2012 - 06:05 PM

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

#13 Juampi Mayoral

Juampi Mayoral

    Member

  • Members
  • PipPip
  • 12 posts

Posted 17 September 2012 - 04: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!

#14 Kun Hernowo Putra

Kun Hernowo Putra

    Newbie

  • Members
  • Pip
  • 6 posts

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users