Welcome Guest, Not a member yet? Register   Sign In
How to use Uploaded Files Library
#1

(This post was last modified: 09-03-2019, 01:42 AM by JerryCode.)

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/[font=Monaco, Consolas, Courier, monospace]get[/font]):
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">
Reply
#2

(This post was last modified: 09-02-2019, 11:11 PM by rmcdahal. Edit Reason: Code Formatted )

First Register service

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

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB