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

Proxy Information
Original URL
gemini://ja.ckdaw.net/post/file-upload-in-silex
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
144.277781 milliseconds
Gemini-to-HTML Time
0.338598 milliseconds

This content has been proxied by September (ba2dc).