2017-08-25 30 views
0

我試圖同時移動一個表單中的五個不同的文件,但只有一個圖像移動。我的數據庫表中每個文件名有五列。上傳的圖像名稱保存在數據庫列中,但唯一的問題是僅移動一個文件而不是所有上傳的文件。以下是代碼:move_uploaded_file兩個或多個不同的圖像名稱只移動一個

//form isValid... 
$post = $form2->getData(); 

      $imageonetmp = $post["imageone"]["tmp_name"]; 
      $imageonename = $post["imageone"]["name"]; 

      $imagetwotmp = $post["imagetwo"]["tmp_name"]; 
      $imagetwoname = $post["imagetwo"]["name"]; 

      $imagethreetmp = $post["imagethree"]["tmp_name"]; 
      $imagethreename = $post["imagethree"]["name"]; 

      $imagefourtmp = $post["imagefour"]["tmp_name"]; 
      $imagefourname = $post["imagefour"]["name"]; 

      $imagefivetmp = $post["imagefive"]["tmp_name"]; 
      $imagefivename = $post["imagefive"]["name"]; 

      $filepath = $this->_dir.$imageonename; 
      $filepath = $this->_dir.$imagetwoname; 
      $filepath = $this->_dir.$imagethreename; 
      $filepath = $this->_dir.$imagefourname; 
      $filepath = $this->_dir.$imagefivename; 


      move_uploaded_file($imageonetmp, $filepath); 
      move_uploaded_file($imagetwotmp, $filepath); 
      move_uploaded_file($imagethreetmp, $filepath); 
      move_uploaded_file($imagefourtmp, $filepath); 
      move_uploaded_file ($imagefivetmp, $filepath); 

/*set image names to db here*/ 
$entityManager->persist($autos); 
      $entityManager->flush(); 

希望有人可以提供幫助。

回答

1

您正在使用相同的變量名$ filepath來寫入文件。這意味着您正在移動每個文件,但會覆蓋之前的移動。

您應該使用不同的變量名稱,例如$ filepath1,$ FILEPATH2等..

或者

$ =文件路徑文件位置... 移動文件...

,並重復。

+0

非常感謝。它現在有效 – dino

相關問題