我试图将表单表中的选定文件表单复制到 php 中的新文件夹。由于某种原因,我似乎无法弄清楚为什么我的代码无法正常工作。有没有办法通过 POST 方法做到这一点。我基本上只想复制文件,如果有通过 Post 方法从表单表中选择的文件。下面是我的代码片段......谢谢!
<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>
下面是发布方法页面“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";
}
}