是否可以通过发布方法复制文件 PHP


Is it Possible To Copy Files PHP via Post Method

im 尝试将表单表中的选定文件复制到 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";
        }
    }

它说。

警告:打开目录(上传''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');

我认为这是因为您的路径指向基础,您应该尝试相对路径或真实且正确的绝对路径。