【发布时间】:2011-01-26 11:53:57
【问题描述】:
我的管理文件夹中有一个名为“repository”的文件夹。该文件夹包含 2 个文件:index.html 和 content.php。当用户创建一个新页面时,php会创建一个用户指定的新文件夹,然后需要将这两个文件复制到该文件夹中,同时将它们留在存储库中。
copy(file,dest) 不起作用。 rename(file,dest) 将文件移动到新文件夹,但我在存储库中丢失了它们。
如何将一个文件夹中的文件复制到新文件夹中而不丢失原文件夹中的文件?
$dest = '../'.$menuLocation.'/'.$pageName;
$file1= "repository/index.html";
$file2= "repository/content.php";
mkdir($dest,0777);
rename($file1,$dest.'/index.html');
rename($file2,$dest.'/content.php');
$menuLocation 和 $pageName 由用户提供。文件在那里,file_exists 返回 true。此外,该目录的创建没有问题。 rename() 也可以,我只是丢失了存储库中的文件。
【问题讨论】:
-
复制应该可以。请发布您的代码。
-
$dest = '../'.$menuLocation.'/'.$pageName; $file1="repository/index.html"; $file2="repository/content.php"; mkdir($dest,0777);重命名($file1,$dest.'/index.html');重命名($file2,$dest.'/content.php'); $menuLocation 和 $pageName 由用户提供。如果文件在那里,file_exists 返回 true。
-
感谢戈登的编辑。直到我添加评论后,我才注意到这一点。今天很忙,脑子很乱。
-
请将
rename更改为copy并将error_reporting(-1);放在您的脚本顶部。它有任何错误吗?另外,请将echo __DIR__;放入脚本中,然后将其输出给我们。 -
我只需要添加 .'/index.html' 和 .'/content.php'。谢谢!