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

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

本文介绍了symfony2如何上传没有教义的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能在symfony2上传文件而不使用教义?有了教义,其例子在这里给出:

是否有一个简单的上传文件的方式,就像在核心PHP中我们有move_uploaded_file()函数,我们可以把上传的文件现在,当我在symfony中提交表单时,这是我在request数组('Symfony \ Component' \\ HttpFoundation \ Request)

  [files] => Symfony \ Component \HttpFoundation\FileBag Object 

[parameters:protected] => Array

[upload_cover] => Symfony \ Component \ HttpFoundation \ File \UploadedFile Object

[test:Symfony\Component\HttpFoundation\File\UploadedFile:private =>>
[originalName:Symfony\Component \HttpFoundation\File\UploadedFile:prime=\"blank_of_success.png
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private => image / png
[size:Symfony \ Component \HttpFoundation\File\UploadedFile: private] => 157958
[error:Symfony \ Component \HttpFoundation\File\UploadedFile:private =>> 0
[pathName:SplFileInfo:private] => C:\xampp\tmp\php3636.tmp
[fileName:SplFileInfo:private] => php3636.tmp






File 对象。

  foreach($ request->文件为$ uploadedFile){
$ name = // ...
$ file = $ uploadedFile-> move($ directory,$ name);

请看以获取该类的全部功能文档。


Is it possible to upload files in symfony2 WITHOUT using doctrine? With doctrine, its example is given here: http://symfony.com/doc/2.2/cookbook/doctrine/file_uploads.html

Is there a simple way to upload files, like in core PHP we have move_uploaded_file() function with which we can move the uploaded to file after the form is submitted.

For now when I submit the form in symfony this is what I get in 'files' section of request array (Symfony\Component\HttpFoundation\Request)

 [files] => Symfony\Component\HttpFoundation\FileBag Object
        (
            [parameters:protected] => Array
                (
                    [upload_cover] => Symfony\Component\HttpFoundation\File\UploadedFile Object
                        (
                            [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
                            [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => secret_of_success.png
                            [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/png
                            [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 157958
                            [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
                            [pathName:SplFileInfo:private] => C:\xampp\tmp\php3636.tmp
                            [fileName:SplFileInfo:private] => php3636.tmp
                        )

                )

        )
解决方案

After submitting the form, move the file to your desired directory and you will get a File object in return.

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

Take a look at the API-Manual for the full featured documentation of this class.

这篇关于symfony2如何上传没有教义的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 13:40