This has been solved. After reviewing the demo of an unrelated app
written in Symfony it took all but seconds to know how multiple file
uploads work.
The trick is to give each upload field a different name. Not the same
name more an aarray
eg
<?php for($i=1; $i <= 5; $i++): ?>
<div class="form-row">
<?php echo label_for('newFile_'.$i, 'File:') ?>
<?php echo input_file_tag('newFile_'.$i) ?>
</div>
<?php endfor; ?>
See the upload field name is
<?php echo input_file_tag('newFile_'.$i) ?>
This then produces this form.
<form method="post" enctype="multipart/form-data" action="/
frontend_dev.php/upload_photo">
<input type="hidden" name="user_id" id="user_id" value="2" />
<fieldset>
<legend>Upload Photos</legend>
<div class="form-row">
<label for="album_parent_id">Parent Album</label> <select
name="album_parent_id" id="album_parent_id"><option value=""></option>
<option value="3">hawkins</option>
<option value="5" selected="selected">-gloria</option>
</select> </div>
<div class="form-row">
<label for="newFile_1">File:</label> <input type="file"
name="newFile_1" id="newFile_1" value="" /> </div>
<div class="form-row">
<label for="newFile_2">File:</label> <input type="file"
name="newFile_2" id="newFile_2" value="" /> </div>
<div class="form-row">
<label for="newFile_3">File:</label> <input type="file"
name="newFile_3" id="newFile_3" value="" /> </div>
<div class="form-row">
<label for="newFile_4">File:</label> <input type="file"
name="newFile_4" id="newFile_4" value="" /> </div>
<div class="form-row">
<label for="newFile_5">File:</label> <input type="file"
name="newFile_5" id="newFile_5" value="" /> </div>
<div>
<input type="submit" name="commit" value="Upload file" /> </div>
</fieldset>
</form>
Because symfony uses the method getFileNames which is using array_keys
each of the uploaded files are made its own array in the $_FILES array
in PHP
when symfony gets the key of this array element it they access all the
elements of the file which has been uploaded by this key. Know
knowing how this works it actually is a good way of doing it. I do
hope this help other who get stuck on this like I did. I am sorry if
this is hard to understand but what I am trying to say is correct and
does work.
On Nov 20, 6:54 pm, lionslair <[EMAIL PROTECTED]> wrote:
> Note: I have posted the on the forum but not really received a lot of
> help or a solution to this yet.
>
> Can someone Please help me with this. I have been trying to work this
> out for hours with no success.
>
> I tried uploading a single file and that worked fine. However when I
> then try and upload multiple files then the result is nothing. No
> error and no file upload.
>
> See my view that makes the form.
>
> <?php echo form_tag('@upload_photo', 'multipart=true') ?>
>
> <?php echo input_hidden_tag('user_id', $sf_user->getProfile()-
>
> >getUserId()); ?>
>
> <fieldset>
> <legend>Upload Photos</legend>
>
> <div class="form-row">
> <?php echo label_for('album_parent_id', 'Parent Album') ?>
> <?php echo select_tag('album_parent_id',options_for_select(
>
> GalleryAlbumTools::nested_dropdown_albums($sf_user->getProfile()->getUserId()),
>
> $sf_params->get('album_parent_id'),
> 'include_blank=true'
> )) ?>
> </div>
> <?php for($i=1; $i <= 5; $i++): ?>
> <div class="form-row">
> <?php echo label_for('newFile', 'File:') ?>
> <?php echo input_file_tag('newFile[]') ?>
> </div>
> <?php endfor; ?>
>
> <div>
> <?php echo submit_tag('Upload file') ?>
> </div>
>
> </fieldset>
> </form>
>
> And the resulting action
>
> /**
> * Execute Action Upload photo
> *
> */
> public function executeUpload()
> {
> if ($this->getRequest()->getMethod() != sfRequest::POST)
> {
>
> return sfView::SUCCESS;
> }
> else
> {
> if ($this->getRequest()->hasFiles())
> {
>
> foreach ($this->getRequest()->getFileNames() as $fileName)
> {
> //$this->logMessage(' uploaded image: '.
> print_r($fileName),'err');
> $fileSize = $this->getRequest()->getFileSize($fileName);
> $fileType = $this->getRequest()->getFileType($fileName);
> $fileError = $this->getRequest()->hasFileError($fileName);
> $fileRealName = $this->getRequest()->getFileName($fileName);
> $uploadDir =
> sfConfig::get('sf_upload_dir').sfConfig::get('app_gallery_picture_folder').
> DIRECTORY_SEPARATOR . $fileName;
> //$uploadDir = sfConfig::get('sf_upload_dir');
>
> $this->getRequest()->moveFile($fileName, $uploadDir);
> } // end foreach
>
> $this->setFlash('class', 'confirmation');
> $this->setFlash('msg', 'Your images have been successfully
> uploaded');
> $this->redirect('@photo_management');
> } // end if file uplaods
>
> } // end if else
>
> } // end function executeUpload
>
> What is it I am doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---