tags:

views:

85

answers:

2

I am learning php, trying to use the fopen() function. The php file I am coding is in this directory /domains/xxxxx.com.au/public_html/phpfile.php What path do I specify for the file to be opened, the example I am looking at is based on a server on a pc where this is the file path $filename = "c:/newfile.txt"; not an online server.

UPDATE!

This is the whole script, I have the file location correct, now the4 script is returning "couldnt create the file" does this have something to do with ther permission of the folder location of the file?

   <?php
$filename = "/domains/xxxxxxxx.com.au/public_html/newfile.txt";
$newfile = @fopen($filename, "w+") or die ("couldnt create the file");
fclose($newfile);
$msg = "<p>File Created</p>";
?>

<HTML>
<HEAD>
</HEAD>
<BODY>

<? echo "$msg" ?>

</BODY>
</HTML>
+2  A: 

Assuming that your php file is inside the public_html too, you could use :

$fp = fopen( "newfile.txt", "rt" );

Or, giving the full path :

$fp = fopen( "/domains/xxxxx.com.au/public_html/newfile.txt", "rt" );

This will open it if it already exists.

Refer to this for further details of opening flags.

UPDATE: You can even use the is_writable/is_readable function to check file access before trying to open it.

Simone Margaritelli
not php but txt file I hope
Col. Shrapnel
sorry, i'm just tired XD
Simone Margaritelli
thanks for the answer, please look at the edited question more problems (storey of my coding life)
Jacksta
A: 

Read http://us2.php.net/manual/en/function.fopen.php Example #1 is relevant for a Unix system.

David Baucum