user3665428 user3665428 - 2 months ago 11
HTML Question

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


Warning: fopen(log_post.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\MyApp\public\index.php on line 3
can't open file


My
index.php
in the public folder:

<?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();
?>


How should i fix that?

Answer

The function fopen has no mode t. You need to specify a mode such as w, a, r, etc., and then append t to use line ending translation mode. Use something like this:

fopen($File, "rt");

Where you can change rt to any valid php mode and t at the end, such as at, wt, r+t, etc.

See here for info: http://www.php.net/manual/en/function.fopen.php