CodeIgniter Forums
How to use Uploaded Files Library - 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: How to use Uploaded Files Library (/showthread.php?tid=74246)



How to use Uploaded Files Library - JerryCode - 09-02-2019

I want upload some files in a Codeigniter4 program

The method in Controller:
Code:
<?php
namespace App\Controllers;
use CodeIgniter\Controller;


class Test extends Controller
{
    ……

    public function get(){
        $file = $this->request->getFile('thumbnail');
        dd($file->getName());
    }
    ……

Result(ci.com/test/get):
Quote:Error
Call to a member function getName() on null

How to use Uploaded Files Library?

Thanks!

This problem has been solved:
The upload file form must contain enctype="multipart/form-data"

Like this:
Code:
<form action="upload_file.php" method="post" enctype="multipart/form-data">



RE: How to use Uploaded Files Library - rmcdahal - 09-02-2019

First Register service

Code:
$file = new \CodeIgniter\Files\File($path);
$file = $this->request->getFile('thumbnail');
        dd($file->getName());



RE: How to use Uploaded Files Library - JerryCode - 09-03-2019

(09-02-2019, 11:10 PM)rmcdahal Wrote: First Register service

Code:
$file = new \CodeIgniter\Files\File($path);
$file = $this->request->getFile('thumbnail');
        dd($file->getName());


I tried this,but got en error:

ErrorException

Undefined variable: path