Newbie problem writing to a file...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BuckeyeTheDog
Forum Newbie
Posts: 5
Joined: Wed Mar 16, 2011 9:19 pm

Newbie problem writing to a file...

Post by BuckeyeTheDog »

Newbie here... Thanks for your help.

I am using the "How to do everything in PHP & MySQL" book. I am learning how to write to a file. I am having problems noted below...

For this php code...

Code: Select all

<?php>
	
	$file = 'WriteTest.txt';

	$fh = fopen($file, 'w') or die('What the hell, this did not work at all.');
	
	fwrite($fh, 'We will see if this really works.') or die('Could not write to file.');

	fclose($fh);
	
?>
I am getting this returned...


Warning: fopen(WriteTest.txt) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/ReadWriteFileExample.php on line 5
What the hell, this did not work at all.

I have ensured that the htdocs folder has read write access. I'm not sure what I am doing wrong.

Any ideas? Thanks in advance, BtD
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Newbie problem writing to a file...

Post by social_experiment »

Is the file WriteTest.text in the same directory as ReadWriteFileExample.php?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply