2011-08-02 45 views
0

我不能上傳同一表格上的多個文件,但並非所有文件都被選中(如果我上傳了所有文件,它可以正常工作)。無法上傳多個文件

相關的代碼:

<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"> 
      <input type="submit" value="Edit" id="button1" /> 
      <input type="reset" id="button2" /> 
     </div> 
    </form> 

和行動(後續代碼var_dump是爲了調試)

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()); 
    } 

回答

1

的所有文件中的字段的名稱是相同的。添加後一[],即

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

由於三個具有相同的名稱,最後一個(空)一個覆蓋第一人。

+0

是的,應該這樣做 –

+0

不是,它們不一樣,foreach中的$ langId變化,以及我檢查過的螢火蟲,它們不同(on-1,off-1,on-2,off-2 )。 – Vadiklk