Page 1 of 1

can't create a file

Posted: Mon Oct 23, 2006 2:49 pm
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?

Posted: Mon Oct 23, 2006 3:02 pm
by hawleyjr
Have you checked our directory permissions?

Posted: Mon Oct 23, 2006 3:07 pm
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. ";
?>

Posted: Mon Oct 23, 2006 3:40 pm
by KG
It was indeed the permissions. Good call hawleyjr, and thanks for the advice volka. Kudos to you both.