如何在提交后将文件复制到另一个目录

时间:2016-01-24 13:27:11

标签: php function copy

我正在尝试在表单提交后创建一个目录,然后在提交表单后,我希望该目录中包含一个文件。我已经尝试了php复制功能并使用了if语句来查看它是否成功复制但事实并非如此。请查看我的代码,看看发生了什么。当它工作时,它只会给出一个" 1"输出一旦提交。没有实际文件移动到文件夹内。

if($_POST['submit']=='Register')
{
// If the Register form has been submitted
$root = "/serves/registered.php";
$err = array();
$folder = mkdir($_POST['username']);
$reg = "registered.php";
mkdir($_POST['username']);
copy($root,$folder);
if (!copy($root, $folder)) {
        echo "failed to copy $root...\n";
} else {
    echo "Account was successfuly created.";
}

谢谢

2 个答案:

答案 0 :(得分:1)

这可以做到:

$root = "serves/registered.php";
$folder = mkdir($_POST['username']);
if($folder) {
    $reg = "registered.php";
    if (!copy($root, $_POST['username']."/".$reg)) {
        echo "failed to copy $root...\n";
    } else {
        echo "Account was successfuly created.";
    }
}
else {
    echo "Could not create folder";
}

答案 1 :(得分:0)

if($_POST['submit']=='Register')
{
    // If the Register form has been submitted
    $root = "contact.php";
    $folder = $_POST['username'] . '/' . $root;
    mkdir($_POST['username']);
    if (!copy($root, $folder)) {
      echo "failed to copy $root...\n";
    } else {
     echo "Account was successfuly created.";
    }
}