我有一个config.php文件:
define('DIRECTORY', 'http://localhost:8080/demo/');
并提交test.php文件
include('config.php');
$file = DIRECTORY . 'cache/list.txt';
$expire = 86400; // 24h
if(file_exists($file) && filemtime($file) > (time() - $expire)) {
$data = unserialize(file_get_contents($file));
} else {
$data = "test";
$output = serialize($data);
$fp = fopen($file, "w");
fputs($fp, $output);
fclose($fp);
}
echo $data;
当我在wampserver中运行test.php时,错误是:
Warning: fopen(http://localhost:8080/demo/cache/list.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in ...
但是当我删除DIRECTORY时,代码运行正常,$file = 'cache/list.txt';
如何解决?
答案 0 :(得分:0)
您应该使用绝对路径而非写入URL。
例如/var/www/cache/list.txt
而不是http://something/cache/list.txt