2010-07-22 79 views
0

我有這段代碼來複制一個html文件並重新命名它。然而,它並沒有這樣做,我已經嘗試過大量的代碼變體,但仍然沒有。我可能只是忽略了一些東西,或者我忘了一些東西。用PHP複製和重命名問題

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

有關如何解決此問題的任何想法?或者一個不同的代碼?提前致謝!

+5

我希望你有更多的代碼比* *剛纔那個... – 2010-07-22 18:54:08

+2

單引號內的$也是字面上的。你需要雙引號才能被解析爲變量。 – 2010-07-22 18:58:34

回答

3

所有你在這裏做的是創建變量,你必須實際上複製文件。查看PHP的copy()函數。

這裏有一個如何使用它的一個例子:

$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

-3

或者你可以做

`$file = 'example.html'; 
$newfile = 'bla.html; 
file_get_contents($file); 
file_put_contents($file,$newfile);` 
+2

這段代碼不會做任何事情,即使您做得正確,也會浪費資源。 – quantumSoup 2010-07-22 19:03:13