dongzhuang6417 2015-07-16 07:38
浏览 54
已采纳

PHP - 将文件复制到文件夹

i have problem to copy same file name ex : 00000.php to the same folder (00000) note : folder & file (.php) was create by "Hash" code. it's my code :

<?php
header ('Location: admin.php');

// Variables
$ads= $_POST['ads'];
$navbar = $_POST['navbar'];
$slider = $_POST['slidermenu'];
$news = $_POST['news'];
$items = $_POST['items'];
$footer = $_POST['footer'];
$rand = md5($_SERVER['REMOTE_ADDR'] . time());
// File Open
chdir("../pages/");
mkdir($rand);
$filename = fopen($cd . $rand . "." . "php" ,"a"); 
copy($filename,$rand);


// Should Include It's Head (Css / Js)
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/settings.php"); ?>');
fwrite($filename,"
");


// Start Function For Radio Boxs
if ($ads == "ads-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/ads.php"); ?>');
fwrite($filename,"
");    
}

if ($navbar== "navbar-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/navbar.php"); ?>');
fwrite($filename,"
");    
}

if ($slider == "slidermenu-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/slider.php"); ?>');
fwrite($filename,"
");    
}

if ($news== "news-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/news.php"); ?>');
fwrite($filename,"
");    
}

if ($items == "items-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/items.php"); ?>');
fwrite($filename,"
");    
}

if ($footer== "footer-yes") {          
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/footer.php"); ?>');
fwrite($filename,"
");    
}
// End Function For Radio Boxs


// File Close
fclose($handle);
exit;
?>

Images : http://i.stack.imgur.com/vjkoT.png

thanks

</div>
  • 写回答

1条回答 默认 最新

  • drrvnbwle80177811 2015-07-16 08:59
    关注

    You don't try to copy a file which is currently opened by PHP before writing data to that file, are you?

    Its like everything on the computer: You should first WRITE the file before trying to copy it.

    ALSO you try to create a file in its folders location.

    What are you copying:

    /example.php to /example -> copy($filename,$rand);
    

    What are you trying to copy:

    /example.php to /example/example.php -> copy($filename,$rand."/".$filename);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法