File uploads not working in symfony server:start

I have a virtualbox VM, running Symfony and the following:

/**
     * @Route("/upload", name="upload")
     */
    public function index(Request $request): Response
    {
        $file = [];

        $form = $this->createFormBuilder($file)
            ->add('file', FileType::class)
            ->getForm();
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $temp = $form->get('file')->getData();
            $path = $temp->getPathname() .DIRECTORY_SEPARATOR.$temp->getClientOriginalName();

            dump($file);
            dump($temp);
            echo file_get_contents($path);
            exit;

            //echo file_get_contents($path);
            //return $this->redirectToRoute('app_product_list');
        }

        return $this->render('upload/index.html.twig', [
            'form' => $form->createView(),
        ]);
    }

Here is the dump:

SymfonyComponentHttpFoundationFileUploadedFile {#19 ▼
  -test: false
  -originalName: "room-color.jpg"
  -mimeType: "image/jpeg"
  -error: 0
  path: "/tmp"
  filename: "phpFlvO7F"
  basename: "phpFlvO7F"
  pathname: "/tmp/phpFlvO7F"
  extension: ""
  realPath: "/tmp/phpFlvO7F"
  aTime: 2020-10-28 22:07:59
  mTime: 2020-10-28 22:07:59
  cTime: 2020-10-28 22:07:59
  inode: 1048391
  size: 114900
  perms: 0100600
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

Here is the error:

Warning: file_get_contents(/tmp/phpFlvO7F/room-color.jpg): failed to open stream: No such file or directory

Pretty self-explanatory but why is it not working? What am I missing?

Here is the generated HTML:

<div class="form-group"><label for="form_file" class="required">File</label><div class="custom-file"><input type="file" id="form_file" name="form[file]" required="required" class="custom-file-input"><label for="form_file" lang="en" class="custom-file-label"></label>
    </div>
</div>

Any ideas?

I’ve tried setting the owner/group of /tmp to vagrant – no dice!!!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *