开发者

Symfony: uploading a file without sfWidgetFormInputFile()

开发者 https://www.devze.com 2023-04-10 06:01 出处:网络
i\'m try开发者_运维知识库ing to develope a file uploading system for my symfony app. I tryed to use the sfWidgetFormInputFile object, but did\'nt know how to use it >_<. Now i\'m trying to do it tr

i'm try开发者_运维知识库ing to develope a file uploading system for my symfony app. I tryed to use the sfWidgetFormInputFile object, but did'nt know how to use it >_<. Now i'm trying to do it traditionally, with a code like this in the view:

<form action="<?php echo url_for('home/saveFile')?>" method="post">
    <input type="file" id="file" name="file">
    <input type="submit" value="Upload">
</form>

How can i access the submitted file information in the action class?

PS: I think i did something wrong in the form because in the symfony dev bar, in config section, in global subsection, there is a parameter called 'files' and is empty. The sent files should be there, right?

Thank you very much for your time! :D


The sfWidgetFileInputFile is a much better way of doing what you want to do ... but if you really want to do it manually - this is what you need in your action.class.php function ->

(where $request is an sfWebRequest object)

foreach ($request->getFiles() as $fileName) {
   $fileSize = $fileName['size'];
   $fileType = $fileName['type'];
   $theFileName = $fileName['name'];
   move_uploaded_file($fileName['tmp_name'], "$newdirectory/$theFileName");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消