PHP-fopen log_post.txt无法打开流:没有这样的文件或目录


PHP - fopen log_post.txt failed to open stream: no such file or directory

警告:fopen(log_post.txt(:无法打开流:在C:''examplep''htdocs''MyApp''public''index.php的第3行中没有这样的文件或目录无法打开文件

公用文件夹中的我的index.php

<?php
$File = "log_post.txt"; 
$fh = fopen($File, 't') or die("can't open file"); 
fwrite($fh, "'n"); 
#$headers = apache_request_headers(); 
#foreach ($headers as $h => $v)
#   fwrite($fh, "$h: $v'n");
#fwrite($fh, print_r($HTTP_RAW_POST_DATA,1));
fclose($fh);
require_once 'Framework/SiteHandler.php';
Zend_Controller_Front::getInstance()
    ->setControllerDirectory('../application/controllers')
    ->throwExceptions(false)
    ->dispatch();
?>

我该怎么解决?

函数fopen没有模式t。您需要指定一个模式,如w、a、r等,然后追加t以使用行尾翻译模式。使用类似的东西:

fopen($File, "rt");

在这里,您可以将rt更改为任何有效的php模式,并在最后更改t,如atwtr+t等。

有关信息,请参阅此处:http://www.php.net/manual/en/function.fopen.php

使用fopen($File, 'a')而不是fopen($File, 't')