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
是否可以在不使用doctrine的情况下上传symfony2中的文件?有了教义,这里给出了它的例子: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.
有没有一种上传文件的简单方法,比如在核心PHP中我们有move_uploaded_file()函数,我们可以在提交表单后将上传到文件。
For now when I submit the form in symfony this is what I get in 'files' section of request array (Symfony\Component\HttpFoundation\Request)
现在,当我在symfony中提交表单时,这就是我在请求数组的'files'部分中获得的内容(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
)
)
)
1 个解决方案
#1
33
After submitting the form, move the file to your desired directory and you will get a File
object in return.
提交表单后,将文件移动到所需的目录,然后您将获得一个File对象作为回报。
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.
请参阅API手册以获取本课程的全功能文档。
#1
33
After submitting the form, move the file to your desired directory and you will get a File
object in return.
提交表单后,将文件移动到所需的目录,然后您将获得一个File对象作为回报。
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.
请参阅API手册以获取本课程的全功能文档。