Page 1 of 1

How to create a new text file?

Posted: Thu Jun 12, 2003 2:45 pm
by slipstream
I am trying to create a text file using this:

$file2=fopen("hello.txt", "a+");
fwrite($file2, "whatever");
fclose($file2);

It never works?

Re: How to create a new text file?

Posted: Thu Jun 12, 2003 3:27 pm
by twigletmac
slipstream wrote:It never works?
Do you get any error messages? Does anything happen?

Mac

Posted: Thu Jun 12, 2003 3:32 pm
by slipstream
actually I am doing 2 things here:

First I write to a specific file:
$docketEntry=$docketNum;
$file=fopen("docket.txt", "a+");
fwrite($file, "\n".$docketEntry);
fclose($file);

then right after I try creating this file like this:
$file2=fopen("hello.txt", "a+");
fwrite($file2, "test");
fclose($file2);

It's very wierd, it writes the value "test" to the first file even though I specify $file2?

Posted: Thu Jun 12, 2003 6:30 pm
by Paddy
Does the $file2 open? You can try to eliminate the problem by doing something like...

Code: Select all

<?php
if (!($file2=fopen("hello.txt","a+")))
{
echo("Could not open file");
}
?>

Posted: Fri Jun 13, 2003 9:42 am
by slipstream
Yes the file is not opening, anyone know why?

Posted: Fri Jun 13, 2003 9:56 am
by volka
try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', TRUE); // debug only
$docketEntry=$docketNum;
$file=fopen("docket.txt", "a+");
fwrite($file, "\n".$docketEntry);
fclose($file);

//then right after I try creating this file like this:
$file2=fopen("hello.txt", "a+");
fwrite($file2, "test");
fclose($file2);
or (if possible) take a look at the messages in the webserver's error-log. It might tell you more than we can guess ;)

Posted: Fri Jun 13, 2003 10:05 am
by slipstream
ok here are my errors

Warning: fopen(hello.txt) [function.fopen]: failed to create stream: Permission denied in /mnt/home/www/mysite.com/www/docket/updateDocket.php on line 11

Warning: fwrite(): supplied argument is not a valid stream resource in /mnt/home/www/mysite.com/www/docket/updateDocket.php on line 12

Warning: fclose(): supplied argument is not a valid stream resource in /mnt/home/www/mysite.com/www/docket/updateDocket.php on line 13


What does it mean?

Posted: Fri Jun 13, 2003 10:20 am
by cactus
You don't have permission to open the file requested, chown it to 777.

Regards,

Posted: Fri Jun 13, 2003 10:32 am
by slipstream
man am I dumb :roll:

Thanks guys, the files were 777 but the folder wasn't. Whew..