bpross
bpross

Reputation: 353

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.

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

?>

Upvotes: 1

Views: 65

Answers (2)

Utkarsh Dixit
Utkarsh Dixit

Reputation: 4275

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

Upvotes: 1

Naktibalda
Naktibalda

Reputation: 14110

You used quotes incorrectly in your code.
Variables are not interpolated inside single quotes.

Change

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

to

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

Upvotes: 2

Related Questions