Php 将单个模板复制到多个文件名
我在创建多文件时遇到了一些问题。我拿到密码了 从我的另一个项目,实际上创建一个页面的时间顺序 试图让它创建给定template.php文件的多个页面 我在日志中没有发现任何错误,在目的地中也没有发现任何错误。 由于对循环的理解不够透彻,它正在迷失方向 提前谢谢Php 将单个模板复制到多个文件名,php,Php,我在创建多文件时遇到了一些问题。我拿到密码了 从我的另一个项目,实际上创建一个页面的时间顺序 试图让它创建给定template.php文件的多个页面 我在日志中没有发现任何错误,在目的地中也没有发现任何错误。 由于对循环的理解不够透彻,它正在迷失方向 提前谢谢 <?php // copy template.php -> page1.php, page2.php, page3.php etc... $area = $_POST["area"]; // Get number of n
<?php
// copy template.php -> page1.php, page2.php, page3.php etc...
$area = $_POST["area"];
// Get number of needed pages
$numberofpages = $_POST["pagenumber"];
// Location of template.php
$templatelocation = "/var/work.files/template.php";
// Send copied files to the requested location.
$filedestination = "/var/work.files/$area";
for ($i = 1; $i < $numberofpages; ++$i) {
// Check if file name is already there. If there is continue to next in order
if (!file_exists($filedestination . '/page'. $i . '.php')) {
// get filename and copy template to it ...
$filename = "page$i.php";
copy('$templatelocation', '$filedestination/$filename');
//continue until number of requested pages created
}
}
?>
您在代码中使用的引号不正确。
变量不在单引号内插值 改变
copy('$templatelocation', '$filedestination/$filename');
到
您的代码不正确,请删除引号
'
,然后插入另一种类型的引号'
或
而不是
copy('$templatelocation', '$filedestination/$filename');
希望这对你有所帮助注意,这些引语并不是“不正确的”,只是他用得不对。如果要使用单引号(
”
),则必须连接字符串。双引号(“
)是对值进行分析的,因此不需要连接。copy($templatelocation,$filedestination./')。$filename)
也可以。这很有帮助。现在我遇到了一些其他错误。它显示了请求的页数和文件名,但请求的名称少了一页,没有创建任何内容。出现无法打开流文件错误。现在开始处理其余的问题。谢谢。我将在另一页上发布该需要。我找到了其余部分。非常感谢。您的第一个示例不是有效的代码--正斜杠必须作为字符串引用。@Chris感谢您告诉我错误。现在我已经更正了它。我给了一个加号,另一个家伙赢了您2分钟。但是谢谢您的帮助。
copy($templatelocation, $filedestination."/".$filename);
copy($templatelocation, "$filedestination/$filename");
copy('$templatelocation', '$filedestination/$filename');