我有问题将同一文件名ex:00000.php复制到同一个文件夹(00000) 注意:文件夹&文件(.php)是由“哈希”代码创建的。 这是我的代码:
<?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,"\n");
// Start Function For Radio Boxs
if ($ads == "ads-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/ads.php"); ?>');
fwrite($filename,"\n");
}
if ($navbar== "navbar-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/navbar.php"); ?>');
fwrite($filename,"\n");
}
if ($slider == "slidermenu-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/slider.php"); ?>');
fwrite($filename,"\n");
}
if ($news== "news-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/news.php"); ?>');
fwrite($filename,"\n");
}
if ($items == "items-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/items.php"); ?>');
fwrite($filename,"\n");
}
if ($footer== "footer-yes") {
fwrite($filename,'<?php include($_SERVER["DOCUMENT_ROOT"] . "/include/footer.php"); ?>');
fwrite($filename,"\n");
}
// End Function For Radio Boxs
// File Close
fclose($handle);
exit;
?>
图片:http://i.stack.imgur.com/vjkoT.png
感谢
答案 0 :(得分:0)
您没有尝试复制当前由PHP打开的文件,然后才将数据写入该文件,是吗?
它就像计算机上的所有内容:在尝试复制文件之前,您应先写入文件。
您还尝试在其文件夹位置创建文件。
你在复制什么:
/example.php to /example -> copy($filename,$rand);
你想复制什么:
/example.php to /example/example.php -> copy($filename,$rand."/".$filename);