I'm trying to write a file from one directory to another. For example, http://www.xxxxxxx.com/admin/upload.php to http://www.xxxxxxx.com/posts/filename.php
I've read that I cannot write a file by using the HTTP path, how do I use a local path?
$ourFileName = "http://www.xxxxxxxx.com/articles/".$thefile.".php";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
The fopen can't be used to create directories. This is because fopen function doesn't create or open folders, it only works with files. The above code creates a path to the file named 'filename'. The directory of the 'filename' is obtained using the 'dirname' function.
in = fopen("path", " r ");
The fopen() function opens a file or URL. Note: When writing to a text file, be sure to use the correct line-ending character! Unix systems use \n, Windows systems use \r\n, and Macintosh systems use \r as the line ending character.
You should use the absolute or relative path to the file on the file system.
<?php
$absolute_path = '/full/path/to/filename.php';
$relative_path = '../posts/filename.php';
// use one of $absolute_path or $relative_path in fopen()
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With