im trying to copy selected files form within a form table to a new folder in php.. For some reason I cant seem to figure out why my code isn't working appropriately. Is there a way to do this via POST method..I basically want to only copy files if there is a file selected from the form table via Post Method. A snippet of my code below... thanksss!!
<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>
Below is the post method page "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";
}
}
It says.
Warning: opendir(uploads\admin_uploads\upload_sounds\mymp3): failed to open dir: No such file or directory in C: ...
So I think the problem is in the path you gave.
Try one of these.
$dir = dir('.\uploads\admin_uploads\upload_sounds');
, $dir = dir('\Myproject\index\uploads\admin_uploads\upload_sounds');
, $dir = dir('..\uploads\admin_uploads\upload_sounds');
I think its because your path is pointing to base and you should try relative path or true and correct absolute path.