CodeIgniter Forums
[solved] File Upload in CI4 does not work? - 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: [solved] File Upload in CI4 does not work? (/showthread.php?tid=76346)



[solved] File Upload in CI4 does not work? - niklas - 05-05-2020

Hello,

here is a short snipper from my project:

My View:
PHP Code:
<?= form_open('user/upload_logo'); ?>
                  <input type="file" name="userfile" />
                  <br><p class="text-right">
                  <input type="submit" class="btn btn-primary" value="upload">
                  </p>
<?= form_close(); ?>

And on the Controller's side:  (Just simple to check if getFiles() is working... )
PHP Code:
    public function upload_logo()
    {
        $files $this->request->getFiles();
        var_dump($files);
    }  

Result is

array(0) { }


Even if I use getFile('userfile') and try validate, move, store, etc. it always returns an error that I am calling a function on null.
So my file is getting lost while uploading Undecided

Anyone know how to fix this?

BR,
Niklas


RE: File Upload in CI4 does not work? - niklas - 05-05-2020

I solved it... while I was searching for something else in the Form Helper Description I found my mistake of this morning :-)

For everybody who will have the same question in the future:

Just use
PHP Code:
form_open_multipart() 
instead of
PHP Code:
form_open() 

it could be that easy Big Grin


RE: [solved] File Upload in CI4 does not work? - pcero - 11-23-2020

man! you saved my life! This should be in the users guide! I have spent hours trying to get mi file upload to work! Thank you!  Big Grin