tags:

views:

22

answers:

2

hello folks, I have a php script that writes a text file to the same directory where the script is.
Now the problem is, the script gets a URL from some other script. Now the new text file is supposed to be written to this provided location from the last step.
The provided location is in URL format: "www.example.com/main/foo/"

Is there a way to write a text file to this particular folder? I am writing from the same machine so I assume it shouldn't be really difficult? thanks for any help cheers Ali


Flexi Comment Box

A: 

look into file_put_contents

<?php
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Append the contents of $person to the file named by $file.
file_put_contents($file, $person, FILE_APPEND);
?>
solomongaby
A: 

You're probably better off writeing using an absolute disk reference rather than a URL. Get the directory path from the URL, identify the absolute path to the web root, and use that to give yourself the full file path.

Mark Baker
well that is exactly not the option. This code is supposed to be deployed on many servers. So to get the absolute disk reference from the URL is not an option. Isn't there a way to write to the URL directory?
Ali Syed
That rather contradicts what your said in your original post: "I am writing from the same machine so I assume it shouldn't be really difficult?"
Mark Baker
well... maybe I couldn't explain it earlier! The PHP-script is supposed to write the TXT file on the same machine where it is being hosted. The same script must be run on many machines, so getting absolute disk directory address is impossible. I script will only have URL address at disposal!
Ali Syed