fwrite() - Trouble getting this to work - Newbee
Moderator: General Moderators
-
greenAlien
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2003 10:08 pm
fwrite() - Trouble getting this to work - Newbee
Hello,
I'm a kook with php.
I decided to snip ASP and go out into the big world of open source.
I'm on a windows machine using 2000 server. IIS without any permissions.
I am trying to get fwrite() to work, but it won't. It seems I can't access the file to write to it. Is there a setting in php.ini that I am missing?
Here's my code:
(It dies at line 4.)
1. <?php
2. $filename = "test.txt";
3. print "Writing to $filename<br>";
4. $fp = fopen( $filename, "w" ) or die("Could not open $filename");
5. fwrite( $fp, "Hello world\n" );
6. fclose( $fp );
7.
8. print "Appending to $filename<br>";
9. $fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
10. fputs( $fp, "And another thing\n" );
11. vfclose( $fp );
12 ?>
I'm a kook with php.
I decided to snip ASP and go out into the big world of open source.
I'm on a windows machine using 2000 server. IIS without any permissions.
I am trying to get fwrite() to work, but it won't. It seems I can't access the file to write to it. Is there a setting in php.ini that I am missing?
Here's my code:
(It dies at line 4.)
1. <?php
2. $filename = "test.txt";
3. print "Writing to $filename<br>";
4. $fp = fopen( $filename, "w" ) or die("Could not open $filename");
5. fwrite( $fp, "Hello world\n" );
6. fclose( $fp );
7.
8. print "Appending to $filename<br>";
9. $fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
10. fputs( $fp, "And another thing\n" );
11. vfclose( $fp );
12 ?>
-
greenAlien
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2003 10:08 pm
-
greenAlien
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2003 10:08 pm
<?php
$filename = "test.txt";
print "Writing to $filename<br>";
$fp = fopen( $filename, "w" ) or die("Could not open $filename");
fwrite( $fp, "Hello world\n" );
fclose( $fp );
print "Appending to $filename<br>";
$fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
fputs( $fp, "And another thing\n" );
fclose( $fp );
?>
$filename = "test.txt";
print "Writing to $filename<br>";
$fp = fopen( $filename, "w" ) or die("Could not open $filename");
fwrite( $fp, "Hello world\n" );
fclose( $fp );
print "Appending to $filename<br>";
$fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
fputs( $fp, "And another thing\n" );
fclose( $fp );
?>
-
greenAlien
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2003 10:08 pm
Yea, that is real real wierd. I cannot think of anything other than permissions that could cause that problem. Try getting rid of everything but the:
If that errors out (Couldn't open test.txt) that my bet is that the file permissions need to be changed.
Code: Select all
$filename = "test.txt";
$fp = fopen($filename, "a") or die ("Couldn't open $filename");
// Rest of code that should write to file "test.txt"I'm agree with nigma and the code is absolutely right. I'm familiar with windows platform and I think you have user Permissions problem. If you are in LAN then talk to admin for getting permissions. If you have rights to access the IIS then follow me: Open the IIS console select your domain or host name, right click on it and select the properties and there is a tab with write, read, execute etc permissions. Make sure to select the read,write and other permissions which you want. And let me know it works for you.
-
greenAlien
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2003 10:08 pm
Too funy! I actually already tried that as well. It didn't work either; but I think I know what it is now...
I transfered the all the files to another machine and the code worked perfectly.
I then began to compare the differences.
The server on both machines (IIS 5) is setup identical.
I am using the same php.ini file on both machines.
The only difference I could find is in phpinfo.php under the security profile.
Example of phpinfo.php settings in fautly machine:
ALLUSERSPROFILE C:\Documents and Settings\All Users
Example of phpinfo.php settings in working machine:
ALLUSERSPROFILE C:\Documents and Settings\All Users.WINNT
My question now is; how do I access these parameters that are displayed in phpinfo.php?
I can't find them in php.ini.
Thanks,
Rob
I transfered the all the files to another machine and the code worked perfectly.
I then began to compare the differences.
The server on both machines (IIS 5) is setup identical.
I am using the same php.ini file on both machines.
The only difference I could find is in phpinfo.php under the security profile.
Example of phpinfo.php settings in fautly machine:
ALLUSERSPROFILE C:\Documents and Settings\All Users
Example of phpinfo.php settings in working machine:
ALLUSERSPROFILE C:\Documents and Settings\All Users.WINNT
My question now is; how do I access these parameters that are displayed in phpinfo.php?
I can't find them in php.ini.
Thanks,
Rob