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

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

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

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
Reply
#3
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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB