2012-03-22 80 views
0

我有一个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是代码运行OK,$file = 'cache/list.txt'; 如何解决它?

+0

不好玩的外部URL文件的命令,你应该检查文件,其绝对路径 – 2012-03-22 02:40:04

+0

的fopen不能写入到一个URL,因为这会需要一个POST或PUT,除非事先设置了流上下文,否则默认情况下不会这样做。 – 2012-03-22 04:41:26

回答

0

您应该使用绝对路径而不是URL来编写。

/var/www/cache/list.txt,而不是http://something/cache/list.txt

相关问题