2013-09-23 116 views
1

即時通訊試圖將表單內的選定文件複製到一個新的文件夾中。由於某種原因,我似乎無法弄清楚爲什麼我的代碼工作不正常。有沒有辦法通過POST方法來做到這一點..我基本上只想複製文件,如果有通過Post Method從表格中選擇一個文件。我的代碼片段下面... thanksss!是否有可能通過Post方法複製文件PHP

 <form name="bm_table" action="getsounds.php" method="post"> 
    <table id="display_user_urls" > 
     <?php 
     $dir = dir('/upload_sounds'); 
     echo "<tr> 
     <td><strong>Mp3 Files</strong></td>"; 
     echo "<td><strong>Add Selected Mp3 To Members Page</strong></td> 
     </tr>"; 
     while(false !== ($file = $dir->read())){ 
      if($file != "." && $file !=".."){ 
       $file1 = basename($file,".mp3"); 
     echo "<tr> 
      <td><a href=\"".$file1."\">".htmlspecialchars($file1)."</a></td> 
      <td><input type=\"checkbox\" name=\"add[]\"value=\"".$file1."\"/></td> 
       </tr>"; 
      } 
     } 
     echo "<input id=\"add_mp3\" type=\"submit\" name=\"add_submit\" value=\"Click Here To Add\"/>"; 
     $dir->close(); 
     ?> 
    </table> 
</form> 

下面是POST方法頁 「getsounds.php」

$files = scandir("uploads\\admin_uploads\\upload_sounds\\{$_POST['add'][0]}"); 

    $source = "uploads\\admin_uploads\\upload_sounds\\"; 

    $destination = "new_uploads48\\"; 
    foreach($files as $file){ 
     if(in_array($file,array(".","..")))continue; 
     if(copy($source.$file,$destination.$file)){ 
      echo "Success"; 
     } 
    } 
+0

你得到的錯誤是什麼? – ncm

+0

我得到2個警告>>警告:opendir(uploads \ admin_uploads \ upload_sounds \ mymp3):無法打開目錄:C:中沒有這樣的文件或目錄:>>> Warning:readdir()期望參數1爲資源,布爾值給出.....非常奇怪,這個腳本確實做了一個新的文件夾,但它的空..我想把文件放在那個文件夾中,通過post方法在複選框的形式中選擇... –

+0

對不起,我忘了跟隨你。讓我檢查你的問題。 – ncm

回答

0

它說。

警告:執行opendir(上傳\ admin_uploads \ upload_sounds \ mymp3):未能打開目錄:C中沒有這樣的文件或目錄:...

所以我覺得這個問題是在路徑你給了。

嘗試其中之一。

$dir = dir('.\uploads\admin_uploads\upload_sounds');$dir = dir('\Myproject\index\uploads\admin_uploads\upload_sounds');$dir = dir('..\uploads\admin_uploads\upload_sounds');

我認爲它的,因爲你的路徑指向基地,而你應該嘗試相對路徑或真實和正確的絕對路徑。

+0

您好,我是那種經常遇到的問題之一,如果您沒有使用框架,您可以編寫類或函數來幫助您輕鬆而無誤地生成html和php路徑。 – ncm

相關問題