You are here: Re: [PHP] Can't save multiple files if I'm using values pulled from another file... « PHP « IT news, forums, messages
Re: [PHP] Can't save multiple files if I'm using values pulled from another file...

Posted by Jochem Maas on 03/03/05 16:22

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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация