Welcome Guest, Not a member yet? Register   Sign In
File upload leads in 'Class "App\Controller\File" not found'
#1

Hi everyone,
I try to upload a file via an upload form and I get the error message 'Class "App\Controllers\File" not found.
The file is not uploaded to the file system.
My Code:
PHP Code:
<?php

namespace App\Controllers;

class 
Invoicing extends BaseController
{
    protected $helpers = ['form''filesystem'];
    
    
public function index()
    {
        $validationRule = [
            'invoicing_file' => [
                'label' => 'Invoicing File',
                'rules' => [
                    'uploaded[invoicing_file]',
                    'mime_in[invoicing_file,application/pdf]',
                ],
            ],
        ];
        if (! $this->validate($validationRule)) {
            $data = ['errors' => $this->validator->getErrors()];

            return view('header').view('invoicing/invoicing_start'$data).view('footer');
        }
        
        $upload_file 
$this->request->getFile('invoicing_file');

        if (! $upload_file->hasMoved()) {
            $filepath WRITEPATH 'uploads/' $upload_file->store();
            
            $data 
= ['uploaded_fileinfo' => new File($filepath)];

            return view('header').view('invoicing/invoicing_success'$data).view('footer');
        }
    }
    

Windows Server
XAMPP
htdocs: public Folder

Is someone able to support me with this issue?

THX in advance.
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...namespaces
https://www.youtube.com/watch?v=ZoOTdYb150M
Reply
#3

Hi,
ich habe das aus der Codeigniter4 Doku und verstehe nicht, was das Problem ist.

Deshalb meine Frage.
Reply
#4

(This post was last modified: 11-19-2023, 03:04 PM by kenjis.)

Namespaces are PHP's basic feature. It is not CI4 specific matter.

Read:
- https://www.w3schools.com/php/php_namespaces.asp
- https://learncodeigniter.net/codeigniter...igniter-4/
- https://www.php.net/manual/en/language.n...ionale.php
Reply
#5

Now I got your Point.

PHP Code:
<?php

new File($filepath


das gehört nicht zu einer CI4 eigenen Klasse, sondern ist eigentlich ein Model o.ä.

Darüber bin ich tatsächlich nicht gestolpert.

Danke.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB