可以将PHP复制到新目录吗?

时间:2014-04-16 08:20:45

标签: php

刚才我学会了如何在服务器中创建新目录。 所以我的问题是可以将PHP文件复制到新创建的目录吗?

这是我想出的

    mkdir('/home/user/public_html/ref/' . $cid . "_" . $gid, 0777);
   copy('/home/user/public_html/ref/index.php' ,'/home/user/public_html/ref/' . $cid . "_" . $gid);

1 个答案:

答案 0 :(得分:0)

使用copy()是正确的,请参阅副本here.

上的PHP文档

他们提供的例子是......

<?php
  $file = 'example.txt';
  $newfile = 'example.txt.bak';

  if (!copy($file, $newfile)) {
      echo "failed to copy $file...\n";
  }
?>

您的语法不正确,因为copy()中的2参数需要是文件名而不是目录(如上例所示)。试试吧。

      mkdir('/home/user/public_html/ref/' . $cid . "_" . $gid, 0777);
   copy('/home/user/public_html/ref/index.php' ,'/home/user/public_html/ref/' . $cid . "_" . $gid . '/index.php');