I have a problem uploading a file in my form using CodeIgniter 4 and I can't find what's wrong. Can you help me, please? The name of the file is ok, the problem is that it doesn't move the file in the specified directory because I get this error: Call to a member function move() on null. WRITEPATH has the value: C:\xampp\htdocs\myproject\writable\
The part of the view where I upload looks like this :
<div class="card-body">
<label for="exampleInputFile">Fisier</label>
<div class="form-group">
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="customFile" id="customFile" required>
<label class="custom-file-label" for="exampleInputFile">Alege Fisierul</label>
</div>
</div>
</div>
</div>
And the part of the controller function where I try to move the file in a specific folder looks like this :
$img = $this->request->getFile('customFile');
$img->move(WRITEPATH . 'uploads');
I take the name of the file with this : $this->request->getVar('customFile')
Thank you !
This worked in Codeigniter 4:
$file = $this->request->getFile('file');
if (!$file->isValid()) {
return $this->fail($file->getErrorString());
}
$file->move(ROOTPATH . 'public\uploads\documents');
$name = $file->getName();
Thank you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With