开发者

Can't upload multiple files

I can't seem to be able to upload several files on the same form, when not all are chosen (if I upload all, it works).

The relevant code:

<form id = "form" name = "form" action="<?php echo URLgenerator::getURL('project', 'group-edit', array('id' => $projectGroup->getId()), 'admin'); ?>" method="post" enctype='multipart/form-data'>
        <?php 
            foreach($langs as $lang):
                $langId = $lang->getId();
                $displayName = $lang->getDisplayName();
        ?>
            <fieldset id="In<?php echo $displayName; ?>">
                <legend id ="<?php echo $langId?>">
                    <?php echo $displayName; ?>: 
                </legend> 
                <label for="name-<?php echo $langId; ?>">Name: </label> 
                <input type="text" id="name-<?php echo $langId; ?>" name="name-<?php echo $langId; ?>" style="width: 500px;" value="<?php echo $projectGroup->getName($lang); ?>" />
                <br />
                <label for="imageOff-<?php echo $langId; ?>">Image Off: </label> 
                <input type="file" id="imageOff-<?php echo $langId; ?>" name="imageOff-<?php echo $langId; ?>" />
                <img src="<?php echo $projectGroup->getImageOffURL($lang); ?>" />
                <br />
                <label for="imageOn-<?php echo $langId; ?>">Image On: </label> 
                <input type="file" id="imageOn-<?php echo $langId; ?>" name="imageOn-<?php echo $langId; ?>" />
                <img src="<?php echo $projectGroup->getImageOnURL($lang); ?>" />
            </fieldset>
        <?php 
            endforeach;
        ?>
        <div align="center">
 开发者_Go百科           <input type="submit" value="Edit" id="button1" /> 
            <input type="reset" id="button2" />
        </div>
    </form>

and the action (the var_dump is for debugging)

public function groupEditAction()
    {
        $id = $this->getRequest()->getParam('id');
        $projectGroup = new ProjectGroup($id);

        $name = Array();
        $langs = LangFuncs::getAllLangs();
        foreach($langs as $lang) {
            $langId = $lang->getId();

            $name[$langId] = $this->getRequest()->getParam("name-$langId");
        }

        $projectGroup->edit(null, $name);

        $upload = new Zend_File_Transfer_Adapter_Http();
        $upload->setDestination(URLgenerator::getTempFolder());
        $upload->receive();
        $info = $upload->getFileInfo();
        var_dump($info);
        return;
        foreach($langs as $lang) {
            $langId = $lang->getId();
            try { 
                if($info["imageOff-$langId"]['tmp_name'] != '') {
                    $projectGroup->uploadImageOff($lang, $info["imageOff-$langId"]['tmp_name']);
                    unlink($info["imageOff-$langId"]['tmp_name']);
                }
                if($info["imageOn-$langId"]['tmp_name'] != '') {
                    $projectGroup->uploadImageOn($lang, $info["imageOn-$langId"]['tmp_name']);
                    unlink($info["imageOn-$langId"]['tmp_name']);
                }
            } 
            catch (Zend_File_Transfer_Exception $e) { 
                $this->_helper->redirector('image-upload', 'error', 'admin', array());
            }
        } 

        $this->_helper->redirector('index', 'project', 'admin', array());
    }


The name of all the file fields is identical. Add a [] after it, i.e.

name="imageOff-<?php echo $langId; ?>[]"

Since all three have the same name, the last (empty) one overwrites the first ones.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜