💾 Archived View for ja.ckdaw.net › post › file-upload-in-silex captured on 2024-12-17 at 09:44:16. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

File Upload in Silex

For some reason I never remember how to save an uploaded file (or the contents of the file, to be specific) in Silex, my favourite Symfony2 based framework. Well, here it is. I hope I'll remember it if I write it down.

// Get the /Symfony\Component\HttpFoundation\File\UploadedFile
// 'file' is the name of the upload file field in the form.
$file = $request->files->get('file')

// Get the contents of the file. $file->getRealPath() returns
// the full path to the temporarily saved file.
$content = file_get_contents($file->getRealPath())

There is a `move` method in `/Symfony\Component\HttpFoundation\File\UploadedFile` but I rarely use it. I usually use Flysystem to abstract the filesystem away.

The PHPLeague: Flysystem

October 19, 2015

Site Navigation

Home

About This Site

Privacy Policy

© 2024 Jackdaw's Nest