CodeIgniter Forums
Server upload file error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Server upload file error (/showthread.php?tid=79272)



Server upload file error - pippuccio76 - 05-20-2021

HI sorry for english in one project i use dropzone to send image or pdf to server with ajax , this is my function :

PHP Code:
    public function dropzone_estratti_conto()
    {
        

        
//recupero le informazioni del file
        $img $this->request->getFile('userfile');

        $targetDir FCPATH '/xyz_xrh/documenti_personali/'.$this->session->get('user_id');


        //recupero tutti i valori via post
        $post $this->request->getPost();

        $post['nome_file_originale'] = $img->getName();
 


        //creo un nome casuale
        $newName =$post['id_isee'].'*estratti_conto*'.time().'*'.$img->getName();
        
        
//lo rinomino
        if($img->move($targetDir$newName)){

            //istanzio il model 
            $isee_documenti_estratto_conto_model = new Isee_documenti_estratto_contoModel();

            $post['nome_file'] =$newName ;

            //inserisco i valori nel db 
            $res=$isee_documenti_estratto_conto_model->save($post);

            $id_tabella $isee_documenti_estratto_conto_model->getInsertID();
         }


            echo "{}";


        
    


The name are stored in db but the file there'arent , how is it possible ?i have more than 1000 record and only this time i have this problem.... Can i add more control to increase security ?


RE: Server upload file error - includebeer - 05-20-2021

Sometime it work and sometime it doesn't? Are sure the filename is a valid filename for your filesystem and the target directory is writable?


RE: Server upload file error - pippuccio76 - 05-20-2021

(05-20-2021, 02:11 PM)includebeer Wrote: Sometime it work and sometime it doesn't? Are sure the filename is a valid filename for your filesystem and the target directory is writable?

I found the file out of folder as $this->session->get('user_id' is empty , how can i prevent it ?


RE: Server upload file error - InsiteFX - 05-21-2021

That tells me that you have an error in your code someplace that is over writing or not saving the users id.

I would backtrace an check my session code.


RE: Server upload file error - pippuccio76 - 05-21-2021

(05-21-2021, 02:51 AM)InsiteFX Wrote: That tells me that you have an error in your code someplace that is over writing or not saving the users id.

I would backtrace an check my session code.


This is the path where i save file :


$targetDir FCPATH '/xyz_xrh/documenti_personali/'.$this->session->get('user_id');

Because the file are uploaded by ajax , to solve the problem i must refresh my project to control if session are set . Is There a way to do this for all page ? 


RE: Server upload file error - InsiteFX - 05-21-2021

Change your code to this and see if you get the same results.

PHP Code:
$targetDir FCPATH '/xyz_xrh/documenti_personali/'.session('user_id'); 

Also what type of sessions are you running file, database etc;


RE: Server upload file error - pippuccio76 - 05-21-2021

(05-21-2021, 04:23 AM)InsiteFX Wrote: Change your code to this and see if you get the same results.

PHP Code:
$targetDir FCPATH '/xyz_xrh/documenti_personali/'.session('user_id'); 

Also what type of sessions are you running file, database etc;

i use file , can i set : 


Code:
$sessionExpiration = 0; 


to prevent ?in this way if browser is open $this->session->get('user_id'is set until the user  close browser


RE: Server upload file error - InsiteFX - 05-21-2021

Yes you can the way I showed you is using the session helper.