-1
<?php
//look in directory and grab the file starttoken.php
copy('tokenmaster/starttoken.php', './starttoken.php');


$filename = './starttoken.php';

if (file_exists($filename)) {
$date = new DateTime();
//add the date    
rename("./starttoken.php", "./tokendone" . $date->format('ydhis') . ".php");
//echo "Rename done";
            echo "";
} else {
echo "File not found";
}
?>

//at a loss to figure out how to create a new directory to place this file into.

//revision - while I can create the new folder now, it seems that my renamed file does not get placed into the new directory, just the root, I must be doing something wrong.

<?php
    $store_path = './';
    $name = date('Y-m-d H-i-s');
    if(!is_dir($store_path.$name)) mkdir($store_path.$name);
    
    copy('tokenmaster/starttoken.php', './starttoken.php');

    $filename = './starttoken.php';

    if (file_exists($filename)) {
        $date = new DateTime();
        rename("./starttoken.php", "./tokendone" . $date->format('ydhis') . ".php");
    }
    
    #... your code
    #build your content and store it e.g. by
    file_put_contents($store_path.$name.'/'.$filename, $yourcontent);
   ?>
MPG
  • 21
  • 4
  • You can create a new directory with [mkdir](https://www.php.net/manual/en/function.mkdir.php) – Bossman Jan 17 '22 at 21:45
  • Im not quite sure how to do that. – MPG Jan 17 '22 at 22:43
  • How do to what? The links we've given both show you how to create a folder....did you look at the examples? Did you try anything? What specific problem are you having? – ADyson Jan 17 '22 at 22:45
  • missed that eye site not that great, thanks ill read through the stacklink. – MPG Jan 18 '22 at 13:52

2 Answers2

1

Answer as requested

<?php
$store_path = './';
$name = date('ydhis');
if(!is_dir($store_path.$name)) mkdir($store_path.$name);

copy('tokenmaster/starttoken.php', './starttoken.php');

$filename = './starttoken.php';

if (file_exists($filename)) {
    $date = new DateTime();
    rename("./starttoken.php", "$name/tokendone" . $date->format('ydhis') . ".php");
    //rename("./starttoken.php", "$name/tokendone" . ".php");
}
?>
MPG
  • 21
  • 4
0

Please, check if this works.

<?php
    $date = new DateTime();
    $store_path = './' . date('Y-m-d H-i-s');
    $file_path = $store_path . '/tokendone' . $date->format('ydhis') . '.php';
    
    if(!is_dir($store_path)) mkdir($store_path);
    
    copy('tokenmaster/starttoken.php', $file_path);
    
    #... your code
    #build your content and store it e.g. by
    file_put_contents($file_path, $yourcontent);
?>
Marcus Vinicius Pompeu
  • 1,219
  • 1
  • 11
  • 24