简体   繁体   English

将单个模板复制到多个文件名

[英]Copy single template to multiple file names

I'm having a little trouble with a multi file creation. 创建多文件时遇到了一些麻烦。 I've taken the code from my another project that actually creates pages one at a time in order. 我从另一个项目中获取了代码,该项目实际上一次创建了一个页面。

Trying to get it to create multiple pages of a given template.php file. 试图使其创建给定template.php文件的多个页面。

I'm not getting any errors in the logs and nothing in destination. 我在日志中没有任何错误,在目的地也没有任何错误。 With not understanding loops well enough it's getting lost. 如果对循环的理解不够好,就会迷路。

Thanks in advance 提前致谢

<?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
    }
}

?>

You used quotes incorrectly in your code. 您在代码中错误地使用了引号。
Variables are not interpolated inside single quotes. 变量不会插在单引号内。

Change 更改

copy('$templatelocation', '$filedestination/$filename');

to

copy($templatelocation, "$filedestination/$filename");

Your code is incorrect just remove the quotes '' and insert another type of quotes "" . 您的代码不正确,只需删除引号''然后插入另一种引号""

  copy($templatelocation, $filedestination."/".$filename);

OR 要么

 copy($templatelocation, "$filedestination/$filename");

instead of 代替

copy('$templatelocation', '$filedestination/$filename');

Hope this helps you 希望这对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM