php - Symfony: uploading a file without sfWidgetFormInputFile()

261

i'm trying 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

934

Answer

Solution:

ThesfWidgetFileInputFile 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 youraction.class.php function ->

(where$request is ansfWebRequest object)

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

People are also looking for solutions to the problem: php - html email issue for a tag value

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.