Foofy wrote:
I'm writing a script that transfers files from a list file and saves
them locally. M
If I use values from the list for the filenames of the saved files, it
appears that none of the files are saved 'cept for the last one. If I
put the values in an array directly in the script file, all is well. I
have confirmed that the values are different and I've tried other
methods to load the file, such as fgets. Here is a simplified version
of my script that has the same problem:
<?php
$linklist = file('links.txt');
foreach ($linklist as $link) {
echo "saving to $link<br>"; // confirm link name
$file = fopen ($link, 'w'); // write dummy text to file
try changing the above line to:
$file = fopen (rtrim($link), 'w'); // write dummy text to file
$link should contain a complete path to the file, or possible a valid URL.
also maybe you should check that your file handle is ok, so maybe do this instead:
if ($file = fopen (rtrim($link), 'w')) {
fwrite($file, 'blah');
fclose($file);
}
also there are the following functions:
is_file()
is_dir()
is_readable()
is_writable()
fwrite($file, 'blah');
fclose($file);
}
?>
And in links.txt I have:
link one
link two
link three
If I run the script, the only file that will have been created is "link
three" or whatever is on the bottom. If however, I replace the first
line with:
$linklist = array("link one", "link two", "link three");
Then the script works as expected. What am I missing? I've wasted three
hours trying to figure this out and I don't know what I could be
screwing up. :(
Foofy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php