2011-09-18 57 views
0
$file = 'my/path/to/htaccess/location/.htaccess'; 

$htaccess = file($file); 

$ht = fopen($htaccess,'a'); 

fwrite($ht,"deny"); 

fclose($ht); 

我試圖通過functions.php修改.htaccess文件,CHMOD設置爲777,任何想法?爲什麼這不能在WordPress的functions.php?

編輯:

剛啓用的錯誤:

Warning: file() [function.file]: URL file-access is disabled in the server configuration in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 133 

Warning: file(http://themes.ibrogra.com/beta/.htaccess) [function.file]: failed to open stream: no suitable wrapper could be found in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 133 

Warning: fopen() [function.fopen]: Filename cannot be empty in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 135 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 137 

Warning: fclose(): supplied argument is not a valid stream resource in /home/tfbox/domains/ibrogram.com/public_html/themes/beta/wp-content/themes/beta/functions.php on line 139 
+0

你會得到哪個錯誤?請描述更多細節 – sanders

+0

@sanders - 我似乎沒有得到一個錯誤,它只是沒有效果。 – daryl

+0

'在服務器配置中禁用URL文件訪問 - '$ file'中的路徑是什麼? –

回答

3

$file = 'http://'.$_SERVER['SERVER_NAME'].'/beta/.htaccess'; 

進行所請求的路徑的HTTP路徑。

這沒有任何意義 - 你想使用文件路徑。

你可以使用

$file = $_SERVER['DOCUMENT_ROOT'].'/beta/.htaccess'; 

代替。

+0

是不行的,如果我使用a。 txt文件。 – daryl

+1

@Brogrammer我修正了這個錯誤。對不起,它開始對我來說是就寢時間:) –