symfony2如何上传没有教义的文件?

没有使用教义,可以在symfony2中上传文件吗? 有了教义,它的例子在这里给出:http://symfony.com/doc/2.2/cookbook/doctrine/file_uploads.html

有没有简单的上传文件的方式,比如在核心PHP中,我们有move_uploaded_file()函数,我们可以在提交表单后将上传的文件移动到文件中。

现在,当我在symfony中提交表单时,这是我在request数组(Symfony Component HttpFoundation Request)的“文件”部分中获得的内容。

 [files] => SymfonyComponentHttpFoundationFileBag Object
        (
            [parameters:protected] => Array
                (
                    [upload_cover] => SymfonyComponentHttpFoundationFileUploadedFile Object
                        (
                            [test:SymfonyComponentHttpFoundationFileUploadedFile:private] => 
                            [originalName:SymfonyComponentHttpFoundationFileUploadedFile:private] => secret_of_success.png
                            [mimeType:SymfonyComponentHttpFoundationFileUploadedFile:private] => image/png
                            [size:SymfonyComponentHttpFoundationFileUploadedFile:private] => 157958
                            [error:SymfonyComponentHttpFoundationFileUploadedFile:private] => 0
                            [pathName:SplFileInfo:private] => C:xampptmpphp3636.tmp
                            [fileName:SplFileInfo:private] => php3636.tmp
                        )

                )

        )

提交表单后,将文件移动到所需的目录,并返回File对象。

foreach($request->files as $uploadedFile) {
    $name = //...
    $file = $uploadedFile->move($directory, $name);
}

查看本手册的全部功能文档的API手册。

链接地址: http://www.djcxy.com/p/63147.html

上一篇: symfony2 how to upload file without doctrine?

下一篇: how should I implement validation on my non