我有以下代码:
$cachefile = "http://www.DOMAIN.com/users/{$user}.php";
$fp = fopen($cachefile, 'w'); // open the cache file "cache/home.html" for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close the file
ob_end_clean(); // Send the output to the browser
chmod($cachefile, 0644);
文件路径无效,因为它会产生以下错误:Warning: chmod() [function.chmod]: No such file or directory in ...
但是,此代码确实:
$cachefile = "{$user}.php";
$fp = fopen($cachefile, 'w'); // open the cache file "cache/home.html" for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close the file
ob_end_clean(); // Send the output to the browser
chmod($cachefile, 0644);
该文件(使用第二个代码块)创建在与创建它的脚本相同的文件夹中。但是,我想将它保存到第一个块的位置。我在 php.net 上查找fopen
并没有看到我做错了什么,但显然我是。
编辑(评论回复):
我也试$cachefile = $_SERVER["DOCUMENT_ROOT"] . "/users/{$user}.php"
了也没用。