Upload files with cakephp 4.2

How can I upload files? Do I have to add a plugin? How can I do that?

Is the documentation lacking in some way? There’s instructions on creating inputs and handling the data. And there’s plugins that are easily located, if you want to use them.

I could save the path of the file in the events table, but the path saved was the phisical path of the file (WWW_ROOT in cakephp), how can I get the logical path of a file to save that in the table? I want to save the url of the file and not the phisical path of linux with all the folders.
This is the code that adds a new record to events table:

    public function add()
    {
        $event = $this->Events->newEmptyEntity();
        if ($this->request->is('post')) {
            $event = $this->Events->patchEntity($event, $this->request->getData());
            $submitted_file = $this->request->getData('submitted_file');
			$event->submitted_file = WWW_ROOT . 'upload/' . $submitted_file->getClientFilename();
			if ($this->Events->save($event)) {
				$type = $submitted_file->getClientMediaType();
                if($type == "image/gif" || $type == "image/jpeg" || $type == "image/x-png") $submitted_file->moveTo(WWW_ROOT . 'upload/' . $submitted_file->getClientFilename());
				$this->Flash->success(__('El suceso ha sido guardado.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('El suceso no pudo ser guardado. Por favor, intente nuevamente.'));
        }
        $affiliates = $this->Events->Affiliates->find('list', ['limit' => 200]);
        $this->set(compact('event', 'affiliates'));
    }

If you don’t want to include WWW_ROOT in the path you save in the entity, then don’t include it. You’re the one that’s creating the string you’re saving, you can put whatever you want there. You just have to make sure that when you reference it in other places, you add that back in.

Other notes:

You are moving the submitted file only if it’s one of a few media types, but you’re saving the entity before that check. If I upload a PDF, you will have a row in your database that refers to a file you don’t have in your filesystem.

You are accepting the user’s filename to save it under. If somebody else has uploaded a file called “IMG0001.jpg”, and I upload one with the same name, there will be a collision and one of the files will be lost.

Thank you for the answer, I deleted the WWW_ROOT to save in the field of the table and worked fine and I’m checking the media type after if ($this->request->is(‘post’)) and is also working fine and I put in the EventsTable.php file a rule that submitted_file is unique.