can't create 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
User avatar
KG
Forum Newbie
Posts: 8
Joined: Tue Sep 26, 2006 4:11 pm
Location: Lexington, KY / Huntsville, AL

can't create a file

Post by KG »

I'm trying to learn how to create files, so i wrote a simple php script that shoulld, theoretically create a new .txt file.

My Code is:

Code: Select all

<?php

$filename = "testFile.txt";
echo "string created. ";

$filehandle = fopen($filename,'w') or die("can't open file");
echo "file opened. ";

fclose($filehandle);
echo "file closed. ";

?>
My Output is:

Code: Select all

string created. can't open file

Can anybody see a problem or how to fix this?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Have you checked our directory permissions?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And make php's error reporting more verbose, maybe it wants to tell you something ;)

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

$filename = "testFile.txt";
echo "string created. ";

$filehandle = fopen($filename,'w') or die("can't open file");
echo "file opened. ";

fclose($filehandle);
echo "file closed. ";
?>
User avatar
KG
Forum Newbie
Posts: 8
Joined: Tue Sep 26, 2006 4:11 pm
Location: Lexington, KY / Huntsville, AL

Post by KG »

It was indeed the permissions. Good call hawleyjr, and thanks for the advice volka. Kudos to you both.
Post Reply