将文件复制到新目录 (PHP)
Copy file into new directory (PHP)
我之前也问过类似的问题,但是不知道怎么问才好。下面我根据从注册表单中获取的用户名创建了一个新目录。我只需要包含复制到刚刚创建的新目录的模板文件。我得到的结果是将文件包含在上一级目录中。新目录是使用用户名创建的,但其目录中不包含模板文件。我在这上面花了好几个小时,这样我就不用再打扰你们了。 我做错了什么?
$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);
});
如果我理解你的话,你想将 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
我之前也问过类似的问题,但是不知道怎么问才好。下面我根据从注册表单中获取的用户名创建了一个新目录。我只需要包含复制到刚刚创建的新目录的模板文件。我得到的结果是将文件包含在上一级目录中。新目录是使用用户名创建的,但其目录中不包含模板文件。我在这上面花了好几个小时,这样我就不用再打扰你们了。 我做错了什么?
$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);
});
如果我理解你的话,你想将 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