简体   繁体   中英

how to copy php file multiple file name using php?

i want to copy same php file using php , working with copying one file, I can copy one file , but I have problem when copying multi files using array.

$copys = file('copy.txt');

foreach($copys as $copy) {
copy('page1.php', '$copy');
}

copy.txt is name files:

page2.php
page3.php
page4.php

i want to copy page1 to page2, page3, page4 ,.. page100

But this code not work !

Could you give me a solution :(

Thanks for any help !

If you want to generate a specific number of copies and the numbers for the new file names you will have to use a for loop

<?php
    $master = 'page1.txt';
    $copy_to = 'page%d.txt';
    $num_copies = 10;

    // start you rloop at 2 so we start copying to `page2.txt`
    // and dont overwrite page1.txt
    for ($i=2; $i < $num_copies+2; $i++) {
        copy($master, sprintf($copy_to, $i));
    }

Do something like this:

$copys = arary('from.txt'=>'to.txt', 'from2.txt'=>'to2.txt');

foreach($copys as $from => $to) {
   copy($form, $to);
}

Or if you want to copy the same file multiple times

$copys = file('copy.txt');

foreach($copys as $to) {
   copy('page1.php', $to.".php");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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