Set_upload_field problem

hello ,

i want some help can you help me;

i dont understand why my code isnot working.

if ( $crud->getState() == 'list'){
				
			$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
			$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));
			//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
		
			//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));

			}elseif ( $state == 'edit') {

				$pkey = $info->primary_key;

				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$r1 = $q->row();

			
				$_SESSION['p']=$r1->folder_file;
				//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
				
				$crud->set_field_upload('file_url','assets/uploads/files/'.$_SESSION['p']);				
				//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$_SESSION['p']);
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
			}else {
				$pkey = $info->primary_key;
				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$row = $q->row();

                                $_SESSION['p'] =  $row->folder_file;
				//$crud->set_field_upload('file_url','assets/uploads/files/2021');
				$crud->set_field_upload('file_url','assets/uploads/files/'.$_SESSION['p']);	
				//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$row->folder_file);
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$_SESSION['p']);
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));

			}
		 }

i am searching the id with select query and pass it to session. After that i use it to

$crud->set_field_upload('file_url','assets/uploads/files/'.$_SESSION['p']);

to set the path of upload folder. i dont understand why get default path. and not this :
assets/uploads/files/2021 ( $_session[‘p’] = ‘2021’ )
I think getstate is not working correctly. However i have checked the getstate value and it was ‘edit’.

so can you help me about that prob ? I am using codeigniter 3 with grocery crud

Hello
Some things

  1. there is an extra parenthesis (}) at the end
  2. you could create a better structure for the states.
    these are likely to do the same
    if ($ crud-> getState () == ‘list’) {

} else {
$ pkey = $ info-> primary_key;

State structure


$state_info = $crud->getStateInfo();
	$operation = $crud->getState();
			if( $operation == 'add' || $operation == 'insert' || $operation == 'insert_validation') { //add
				//code
			} elseif( $operation == 'edit' || $operation == 'update' || $operation == 'update_validation')	{ //edit
				//code
				IF (){
					//code
				} else {
					//code
				}
			} else { //list
				//code
 			}

exists
$ r1-> folder_file;
or
$ r1-> file_url;

in edit state you should create an IF for some condition if it is the case
} elseif ($ state == ‘edit’) {

this is being treated as a list
} else {

I use google translator for this answer
GC1.6.4
CI3

Where can I find the possible values of $crud->getStateInfo(); and $crud->getState(); The documentation gives only a small example.
Thank you.

API and Functions list

getState
GC 1.6.4

Thank you! I see them now. It’s in the doc for Grocery Crud 1.x
I’m on 2,x enterprise. The documentation for 2.x is very sparse. The actual values are note to be found there. I will bookmark the old documentation. use in case.

hello again … ,
i dont understand why the if ( $state == ‘edit’ ) is not working right.

I made the changes as you said but nothing …

i have another getState() few lines before for other reason
but i dont think that is problem …

i dont understand why set_field_upload getting the default path … assets/upload/files

i have another getState() few lines before for other reason
but i dont think that is problem …

Hello
and what is that other reason, could you show the code

You already say it here, and maybe you have it declared with another variable, one, only one time

set_field_upload
If it is different, it should go in each state of the controller, if there is a file upload after the state, it will take that last value

Take everything that takes change for the state of the controllers (Add, edit, etc)

this is the full code of my controller !

public function doc_inc()
	{
		
		//$value_i = $this->mymodel->testing();
		
		$crud = new grocery_CRUD();

		$crud->set_theme('datatables');
		$crud->set_table('docs');
		//$crud->set_relation('doc_type','docs','doc_type');
		$crud->columns('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','recipient','recipient_email','sender_id','file_url');
		$crud->display_as('date','Hμερ/νία')
			 ->display_as('doc_type','Τύπος Εγγράφου')
			 ->display_as('protocol_id','Αρ.Πρ.')
			 ->display_as('date_ap','Ημερ/νία Απ/λής-Παρ/βής')
			 ->display_as('sender_rcver','Aποστ-Παρ/της')
			 ->display_as('email_s_r','Email')
			 ->display_as('subject','Θέμα')
			 ->display_as('assignment','Ανάθεση')
			 ->display_as('email_assignment','Email Ανάθεσης')
			 ->display_as('recipient','Παραλήπτης Εσωτερικού')
			 ->display_as('recipient_email','Email Παρ/πτη Εσωτερικού')
			 ->display_as('inserted_by','Εισαγωγή από')
			 ->display_as('modified_by','Τροποιήθηκε από')
			 ->display_as('receiver_id','Αρ.Πρωτ.Παραλήπτη')
			 ->display_as('sender_id','Αρ.Πρωτ.Αποστολέα')
			 ->display_as('cc','Κοινοποίηση')
			 ->display_as('email_cc','Email Κοινοποίησης')
			 ->display_as('briefing','Ενημέρωση')
			 ->display_as('briefing_email','Email Ενημέρωσης')
			 ->display_as('doc_status','Κατάσταση Εγγράφου')
			 ->display_as('zip_file_attach','Συμπληρωματικό Επισυναπτόμενο');
		$crud->set_subject('docs');
		$crud->unset_columns('email_s_r','email_assignment','recipient_email','recipient');
		//$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','file_url');

		$crud->callback_edit_field('email_assignment', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="email_assignment" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('briefing_email', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="briefing_email" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('email_cc', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="email_cc" placeholder="Αφορά Eξερχόμενο ή Εσωτερικό Έγγραφο...">';
        });
        $crud->callback_edit_field('recipient_email', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="recipient_email" placeholder="Αφορά Εσωτερικό Έγγραφο...">';
        });
        $crud->callback_edit_field('sender_id', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="sender_id" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('receiver_id', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="receiver_id" placeholder="Αφορά Εξερχόμενο Έγγραφο...">';
        });
		$state = $crud->getState();
		$info = $crud->getStateInfo();		
		if ( $state == 'edit'){
			$dc = $this->_get_doc_type($info->primary_key);
			$this->session->set_userdata('doc_type',$dc);
			if ($dc=='Εισερχόμενο'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin')
				{
					
					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else {
			
				    $crud->unset_edit_fields('cc','email_cc','recipient','recipient_email','receiver_id');
				}
				
			}

			if ($dc == 'Εξερχόμενο'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin'){

					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else{

				$crud->unset_edit_fields('briefing','briefing_email','assignment','email_assignment','recipient','recipient_email','sender_id');
				}
			}

			if ($dc == 'Εσωτερικό'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin'){
					
					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else {

				$crud->unset_edit_fields('briefing','briefing_email','assignment','email_assignment','date_ap','receiver_id','sender_id');
				}
			}



			$crud->field_type('doc_status','readonly');	
			$crud->field_type('inserted_by','readonly');	
			$crud->field_type('modified_by','readonly');
			$crud->field_type('folder_file','readonly');
		}// end if state 

		

		$crud->field_type('doc_type','dropdown',
            array('Εισερχόμενο' => 'Εισερχόμενο', 'Εξερχόμενο' => 'Εξερχόμενο','Εσωτερικό' => 'Εσωτερικό'));
		
		
		/*if ($this->session->userdata('schacUserStatus')!='nocappsadmin'){
			$crud->unset_fields('inserted_by');
		}*/


		$crud->order_by('date','desc');

		$crud->callback_after_update(array($this, 'modified_by'));
		$crud->callback_column('doc_type',array($this,'_callback_doc_type_highlight'));
		$crud->callback_column('assignment',array($this,'_callback_assignment_wrap'));
		//$crud->callback_column('protocol_id',array($this,'_callback_protocol_id_wrap'));
		$crud->field_type('protocol_id','readonly');
		
		$crud->unset_clone();
		$crud->unset_add();
		$crud->unset_print();
		//$crud->unset_export();

		if ($this->session->userdata('schacUserStatus')=='eprotocoluser')
		{
			$crud->unset_delete();
			$crud->unset_edit();
		}
		if ($this->session->userdata('schacUserStatus') == 'eprotocoladmin'){
			$crud->unset_delete();
		}
		/* resend document */
		$crud->add_action('','','main/resendmail','fa fa-envelope-o fa-2x','');
 
		
		/*$this->db->select('folder_file');
		$this->db->where('id', 239);
		$q = $this->db->get('docs');
		$row = $q->row();*/
		//$crud->callback_before_upload(array($this,'get_folder'));

                //here is the code that i am saying..... the set_field_load not working. 
                //when i am editing a record for upload a file, upload file goes to default path but not to my defined path... why ? the var_dump value has the right value 'edit from getState() function.
		/*$path = '/assets/uploads/files/'.date('Y');
		if (!is_dir($path)) {*/
			$state = $crud->getState();
			var_dump($state);
			if ( $state == 'edit'){

				/*$pkey = $info->primary_key;

				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$r1 = $q->row();*/

			
			
				$crud->set_field_upload('file_url','assets/uploads/files/2021');
				
				//$crud->set_field_upload('file_url','assets/uploads/files/'.$r1->folder_file);				
				//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
			
				
			

			}elseif($state == 'list') {

			$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
			$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));
			//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
		
			//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				

			}

				

		 //}
		//$crud->add_action('Project_Details', '', '','ui-icon-plus',array($this,'get_id'));
		//$crud->add_action('Project_Details', '', 'examples/proj_details','ui-icon-plus');
	
		$output = $crud->render();
		if ( $this->session->userdata('is_authenticated') ){
			$this->_example_output($output);
		}else {
			redirect('Main');
		}
	
	}

Exactly,

you have two functions $crud-> getState

This code comment it for a moment

			$state = $crud->getState();
			var_dump($state);
			if ( $state == 'edit'){

				/*$pkey = $info->primary_key;

				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$r1 = $q->row();*/

			
			
				$crud->set_field_upload('file_url','assets/uploads/files/2021');
				
				//$crud->set_field_upload('file_url','assets/uploads/files/'.$r1->folder_file);				
				//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
			
				
			

			}elseif($state == 'list') {

			$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
			$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));
			//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
		
			//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				

			}

These lines of code

$crud->set_field_upload('file_url','assets/uploads/files/2021');
$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');

Before

$crud->field_type('doc_status','readonly');	
$crud->field_type('inserted_by','readonly');	
$crud->field_type('modified_by','readonly');
$crud->field_type('folder_file','readonly');

And these lines out of state edit

$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));

I insist on this structure

$state_info = $crud->getStateInfo();
	$operation = $crud->getState();
			if( $operation == 'add' || $operation == 'insert' || $operation == 'insert_validation') { //add
				//code
			} elseif( $operation == 'edit' || $operation == 'update' || $operation == 'update_validation')	{ //edit
				//code
				IF (){
					//code
				} else {
					//code
				}
			} else { //list
				//code
 			}

I had removed the second getState() but nothing.

the structure I think is not so bad.

I am getting the state first and after that check with if then else the content of this value is edit.

The var dump value has the value ‘edit’ so if if you click to edit, the state value gets the value ‘edit’. After that, the state value has this content ‘edit’ . So the value $state = getState(); working good.

But the problem is that if $state == ‘edit’ and its true and enter inside the if brackets , the set_field_upload function is not working well and getting the default path which is assets/uploads/files and not my path …

why ? this shows that my path is not working … is empty and getting the default.

some days without going through here
mmmm that’s a simple GC1.6.x functionality

Set upload field

Maybe he is doing something with this code that he has here when he is in the list state

			}elseif($state == 'list') {

			$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
			$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));

but in reality it is a very simple functionality and more using static paths

hello mariel_alberto
this functions import the path of upload files in different folders on list mode.
e.g. if we have a folder with the year (2021) and upload files there. if the year has changed (2022) we will lose the connection with older files … so with this function we are setting the path from a field inside database with name ‘2020 , 2021’ etc.

public function _callback_upload_zip_field($value,$row){

		return "<a href='".site_url('assets/uploads/files/'.$row->folder_file)."/".$row->zip_file_attach."' target='_blank'>$row->zip_file_attach</a>";

	}

my problem is why set_upload_field function not working properly

if you are on list GC you see a list of records so the code is ’ if ( $state == ‘list’) { }
else
if you are on edit mode we have ’ elseif ( $state == ‘edit’ ) { }
but on edit mode the set_upload_field gets the default path , not my defined path … why ?

$crud->set_field_upload('file_url','assets/uploads/files/2021');
$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');

hello mariel_alberto ,

here is the code from this function :

skip comments.

public function doc_inc()
	{
		
		//$value_i = $this->mymodel->testing();
		
		$crud = new grocery_CRUD();

		$crud->set_theme('datatables');
		$crud->set_table('docs');
		//$crud->set_relation('doc_type','docs','doc_type');
		$crud->columns('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','recipient','recipient_email','sender_id','file_url');
		$crud->display_as('date','Hμερ/νία')
			 ->display_as('doc_type','Τύπος Εγγράφου')
			 ->display_as('protocol_id','Αρ.Πρ.')
			 ->display_as('date_ap','Ημερ/νία Απ/λής-Παρ/βής')
			 ->display_as('sender_rcver','Aποστ-Παρ/της')
			 ->display_as('email_s_r','Email')
			 ->display_as('subject','Θέμα')
			 ->display_as('assignment','Ανάθεση')
			 ->display_as('email_assignment','Email Ανάθεσης')
			 ->display_as('recipient','Παραλήπτης Εσωτερικού')
			 ->display_as('recipient_email','Email Παρ/πτη Εσωτερικού')
			 ->display_as('inserted_by','Εισαγωγή από')
			 ->display_as('modified_by','Τροποιήθηκε από')
			 ->display_as('receiver_id','Αρ.Πρωτ.Παραλήπτη')
			 ->display_as('sender_id','Αρ.Πρωτ.Αποστολέα')
			 ->display_as('cc','Κοινοποίηση')
			 ->display_as('email_cc','Email Κοινοποίησης')
			 ->display_as('briefing','Ενημέρωση')
			 ->display_as('briefing_email','Email Ενημέρωσης')
			 ->display_as('doc_status','Κατάσταση Εγγράφου')
			 ->display_as('zip_file_attach','Συμπληρωματικό Επισυναπτόμενο');
		$crud->set_subject('docs');
		$crud->unset_columns('email_s_r','email_assignment','recipient_email','recipient');
		//$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','file_url');

		$crud->callback_edit_field('email_assignment', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="email_assignment" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('briefing_email', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="briefing_email" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('email_cc', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="email_cc" placeholder="Αφορά Eξερχόμενο ή Εσωτερικό Έγγραφο...">';
        });
        $crud->callback_edit_field('recipient_email', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="recipient_email" placeholder="Αφορά Εσωτερικό Έγγραφο...">';
        });
        $crud->callback_edit_field('sender_id', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="sender_id" placeholder="Αφορά Εισερχόμενο Έγγραφο...">';
        });
        $crud->callback_edit_field('receiver_id', function ($value, $primary_key) {
            return '<input type="text" value="'.$value.'" name="receiver_id" placeholder="Αφορά Εξερχόμενο Έγγραφο...">';
        });
		$state = $crud->getState();
		$info = $crud->getStateInfo();		
		if ( $state == 'edit'){
			$dc = $this->_get_doc_type($info->primary_key);
			$this->session->set_userdata('doc_type',$dc);
			if ($dc=='Εισερχόμενο'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin')
				{
					
					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else {
			
				    $crud->unset_edit_fields('cc','email_cc','recipient','recipient_email','receiver_id');
				}
				
			}

			if ($dc == 'Εξερχόμενο'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin'){

					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else{

				$crud->unset_edit_fields('briefing','briefing_email','assignment','email_assignment','recipient','recipient_email','sender_id');
				}
			}

			if ($dc == 'Εσωτερικό'){

				if($this->session->userdata('schacUserStatus')=='nocappsadmin' || $this->session->userdata('schacUserStatus')=='eprotocoladmin'){
					
					$crud->fields('date','doc_type','protocol_id','date_ap','sender_rcver','email_s_r','subject','assignment','email_assignment','briefing','briefing_email','recipient','recipient_email','cc','email_cc','sender_id','receiver_id','file_url','zip_file_attach');
				}else {

				$crud->unset_edit_fields('briefing','briefing_email','assignment','email_assignment','date_ap','receiver_id','sender_id');
				}
			}



			$crud->field_type('doc_status','readonly');	
			$crud->field_type('inserted_by','readonly');	
			$crud->field_type('modified_by','readonly');
			$crud->field_type('folder_file','readonly');
		}// end if state 

		

		$crud->field_type('doc_type','dropdown',
            array('Εισερχόμενο' => 'Εισερχόμενο', 'Εξερχόμενο' => 'Εξερχόμενο','Εσωτερικό' => 'Εσωτερικό'));
		
		
		/*if ($this->session->userdata('schacUserStatus')!='nocappsadmin'){
			$crud->unset_fields('inserted_by');
		}*/


		$crud->order_by('date','desc');

		$crud->callback_after_update(array($this, 'modified_by'));
		$crud->callback_column('doc_type',array($this,'_callback_doc_type_highlight'));
		$crud->callback_column('assignment',array($this,'_callback_assignment_wrap'));
		//$crud->callback_column('protocol_id',array($this,'_callback_protocol_id_wrap'));
		$crud->field_type('protocol_id','readonly');
		
		$crud->unset_clone();
		$crud->unset_add();
		$crud->unset_print();
		//$crud->unset_export();

		if ($this->session->userdata('schacUserStatus')=='eprotocoluser')
		{
			$crud->unset_delete();
			$crud->unset_edit();
		}
		if ($this->session->userdata('schacUserStatus') == 'eprotocoladmin'){
			$crud->unset_delete();
		}
		/* resend document */
		$crud->add_action('','','main/resendmail','fa fa-envelope-o fa-2x','');
 
		
		/*$this->db->select('folder_file');
		$this->db->where('id', 239);
		$q = $this->db->get('docs');
		$row = $q->row();*/
		//$crud->callback_before_upload(array($this,'get_folder'));

		$path = '/assets/uploads/files/'.date('Y');
		//if (is_dir($path)) {
			if ( $crud->getState() == 'list'){
				
			$crud->callback_column('file_url',array($this,'_callback_upload_file_field'));
			$crud->callback_column('zip_file_attach',array($this,'_callback_upload_zip_field'));
			//$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
		
			//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));

			}elseif ( $crud->getState() == 'edit') {
				$_SESSION['state'] = $crud->getState();
				$pkey = $info->primary_key;

				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$r1 = $q->row();

			
				//$_SESSION['p']=$p1;
				$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('file_url','assets/uploads/files/'.$r1->folder_file);
				//$crud->set_field_upload('file_url','assets/uploads/files/2021');				
			//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/2021');
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$r1->folder_file);
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
			}else {
				$_SESSION['state'] = $crud->getState();
				$pkey = $info->primary_key;
				$this->db->where('id', $pkey);
				$q = $this->db->get('docs');
				$row = $q->row();

				//$_SESSION['zip_file_attach'] = $row->folder_file;
				//$crud->set_field_upload('file_url','assets/uploads/files/'.$row->folder_file);
				//$crud->set_field_upload('file_url','assets/uploads/files/2021');
				$crud->set_field_upload('file_url','assets/uploads/files/'.date('Y'));
				//$crud->set_field_upload('file_url',$this->verify_path_callback($path));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.$row->folder_file);
				$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));
				//$crud->callback_before_upload(array($this,'_callback_before_upload'));
				//$crud->set_field_upload('zip_file_attach','assets/uploads/files/'.date('Y'));

			}
		 //}
		//$crud->add_action('Project_Details', '', '','ui-icon-plus',array($this,'get_id'));
		//$crud->add_action('Project_Details', '', 'examples/proj_details','ui-icon-plus');
		
		$output = $crud->render();
		if ( $this->session->userdata('is_authenticated') ){
			$this->_example_output($output);
		}else {
			redirect('Main');
		}
	
	}

Hello there
from the first post I have recommended the importance of a state structure.
You must organize your code, it is repeating the state of edit and list.
More or less on lines 50…59 and 150…159
edit

		if ( $state == 'edit'){
			$dc = $this->_get_doc_type($info->primary_key);
			$this->session->set_userdata('doc_type',$dc);
			}elseif ( $crud->getState() == 'edit') {
				$_SESSION['state'] = $crud->getState();
				$pkey = $info->primary_key;

list

			if ( $crud->getState() == 'list'){`

What status is this code

			}else {
				$_SESSION['state'] = $crud->getState();
				$pkey = $info->primary_key;

I don’t think you have a problem in the set_field_upload function, I think you should organize your code more and try to clean it up a bit more and remove everything you are not using.

Everything that is in the state of editing put that code there as for example.
callback_edit_field

Check well this post has been very long and I do not believe as I said before that the problem is in the set_fleld_upload function

GetState

this is two independent if for getState == edit

this is not right?

if ( $state == 'edit'){
			$dc = $this->_get_doc_type($info->primary_key);
			$this->session->set_userdata('doc_type',$dc);
......

} // end if state

and a few lines below i use it again… i cant ?

no you can’t, only in one state

most likely you are running the second edit

you have to create everything in a single edit state

status edit in url

$this->uri->segment(3)

the same applies to the list state

You either whistle or stick your tongue out, but you can’t do both at the same time

I advise you to go through the functions of GC 1.6.x

API and Functions list

1 Like

@cbabekos , I have read quickly the post, and I think the problem is not major as you may feel. Please, what do you mean by “get default path”? which path are you getting?

I understand you want to upload the files in assets/uploads/files/2021
In which path are they being uploaded ??

I don’t think you can do this @cbabekos .

It would make sense if you use one call to this if , and put all the code you need in there…
Your code needs a lot of cleaning, by the way.
I advise you to use a uniform way … like below…

function name() {
  vars;
  if (condition) {
    commands;
  } else {
    other_commands;
  }
}

The path that i want to upload the file is the assets/uploads/files/2021 but when i use a query to get the database field and append it to assets/uploads/files/'.$file_folder of set_field_upload argument, when i am trying to upload a file , the function uses the default upload_dir which is assets/uploads/files .
why?
As i said i am using a query to get the folder_file value and the value is not empty. why is using the default? Only when I trigger the upload function.