为什么这在WordPress functions.php中不起作用?

时间:2011-09-18 20:59:31

标签: php wordpress file .htaccess chmod

$file = 'my/path/to/htaccess/location/.htaccess';

$htaccess = file($file);

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

fwrite($ht,"deny");

fclose($ht);

我正在尝试通过functions.php修改.htaccess文件,CHMOD设置为777,有什么想法吗?

修改

刚启用错误:

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

1 个答案:

答案 0 :(得分:3)

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

使请求的路径成为http路径。

这没有意义 - 你想使用文件路径。

您可以使用

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

代替。