How to use php fopen () correctly

I am learning php trying to use a function fopen(). The php file that I am encoding is in this directory. /domains/xxxxx.com.au/public_html/phpfile.php What path should I specify for an open file, the example I'm looking for is based on a server on a computer, where is the path to the file $filename = "c:/newfile.txt";, not the Internet server.

UPDATE!

This is the whole script, I have the correct file location, now <4> w371> "can not create the file" is returned. Does this have anything to do with the permission of the folder in the file folder?

   <?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>
+3
source share
2 answers

Assuming your php file is inside public_html, you can use:

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

Or by specifying the full path:

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

This will open it if it already exists.

. .

UPDATE: is_writable/is_readable , .

+3

Source: https://habr.com/ru/post/1741264/


All Articles