Welcome Guest, Not a member yet? Register   Sign In
Server upload file error
#1

(This post was last modified: 05-20-2021, 10:57 AM by pippuccio76.)

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 ?
Reply
#2

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?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(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 ?
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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 ? 
Reply
#6

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;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(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
Reply
#8

Yes you can the way I showed you is using the session helper.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB