tags:

views:

46

answers:

2

I have this code to copy an html file and rename it. However it doesn't do this, and I have tried tons of variations of the code but still nothing. I'm probably just overlooking something, or I forgot something.

$file = 'example.html';
$newfile = '$bla.html;

Any ideas on how to fix this? Or a different code? Thanks in advance!

+3  A: 

All you're doing here is creating variables, you have to actually copy the file. Check out PHP's copy() function.

Here's an example of how to use it:

$file = 'example.txt'; //path to source file, not just the filename
$newfile = 'example.txt.bak'; //same for this string as above

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}

http://php.net/manual/en/function.copy.php

jordanstephens
A: 

Alternatively you can do

`$file = 'example.html';

$newfile = 'bla.html;

file_get_contents($file);

file_put_contents($file,$newfile);`

btrandom
This code doesn't do anything AND would be a waste of resources even if you did it correctly.
quantumSoup