Search code examples
file-uploadsymfony1savefilesystemsaction

How to upload a file in Symfony 1.2 without using a specific form


I haven't done much file uploading in Symfony to this point and I'm trying to figure out how to do it in 1.2+

I can get the files submitted to the action and retrieve them via:

$files = $request->getFiles();

How can I get then save the file to the file system? I don't see any documentation besides the old 1.0 depreciated code.

It looks like this has been moved somehow into the form system but I don't have a specific for for this one-off page that I have that does nothing but upload a few files.

How can I save these files to disc.


Solution

  • If you are not looking to upload the files using the symfony forms then the following coded will also work:

    foreach($request->getFiles() as $file)
    {
        move_uploaded_file($file["tmp_name"], $directory . "/" . $file['name']);
    }