How to create a new text file?
Moderator: General Moderators
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
How to create a new text file?
I am trying to create a text file using this:
$file2=fopen("hello.txt", "a+");
fwrite($file2, "whatever");
fclose($file2);
It never works?
$file2=fopen("hello.txt", "a+");
fwrite($file2, "whatever");
fclose($file2);
It never works?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Re: How to create a new text file?
Do you get any error messages? Does anything happen?slipstream wrote:It never works?
Mac
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
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?
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?
-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
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");
}
?>-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
tryor (if possible) take a look at the messages in the webserver's error-log. It might tell you more than we can guess 
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);-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
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?
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?
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada