1

我之前问过类似的问题,但之前不知道怎么问。下面我根据从注册表单中获取的用户名创建了一个新目录。我只需要包含复制到刚刚创建的新目录的模板文件。我得到的结果是将文件包含在上一级的目录中。新目录是使用用户名创建的,但其目录中不包含模板文件。我为此花了几个小时,所以我不必再打扰你们了。我究竟做错了什么?

 $folder = DIRECTORY_SEPARATOR; // adds the forward slash
   $name = $user->username;   // included from a login script I purchased 
   $thisdir = "../associate"; // desired directory
   $folderPath = $thisdir . $folder . $name;
   $file = copy('../associate/joshua/career.php', $folderPath.'.php'); // copy this file into new directory
        if(!file_exists($folderPath)){
            mkdir($folderPath);
            chmod($folderPath,0777);
        }

     file_put_contents(realpath($folderPath) .'/'. $folderPath, $file);

    });
4

1 回答 1

3

如果我理解你,你想将 career.php 模板从 /associates/ 文件夹复制到 /associates/username/ 文件夹

   $rootfolder = $_SERVER['DOCUMENT_ROOT'];
   $name = $user->username;  
   $thisdir = "/associate/";
   $folderPath = $rootfolder.$thisdir.$name."/"; // desired directory

if(!is_dir($folderPath)){
        mkdir($folderPath, 0777, true);
    }
$currentfile = $rootfolder.$thisdir.'joshua/career.php';
    $destination = $folderPath.'career.php';
  copy($currentfile, $destination); // copy this file into new directory
于 2015-09-07T22:23:01.427 回答