Welcome Guest, Not a member yet? Register   Sign In
[solved] File Upload in CI4 does not work?

(This post was last modified: 05-05-2020, 07:25 AM by niklas.)


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">
<?= 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();

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?


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:
instead of
PHP Code:

it could be that easy Big Grin
Thumbs Up 

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

Theme © iAndrew 2016 - Forum software by © MyBB