symfony2 how to upload file without doctrine?
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 (SymfonyComponentHttpFoundationRequest)
[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
)
)
)
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.
链接地址: http://www.djcxy.com/p/63148.html上一篇: Symfony2:显示Bootstrap开关按钮并获取控制器中的选定值
下一篇: symfony2如何上传没有教义的文件?