Shawn Wilson wrote:[color=blue]
>
> Jane Doe wrote:[color=green]
> >
> > Hi,
> >
> > I need to add a download function in a VB program, but since a file
> > can be located anywhere in our /download section on the web, I was
> > thinking of putting a PHP script there that would take the filename as
> > parameter, and browse through the /download directory to look for this
> > file, including sub-directories, and return the URL, ie.
> >
> > IN
> >
http://www.acme.com/download/find.php?file=myfile.txt
> >
> > OUT
> >
www.acme.com.com/download/sub1/myfile.txt
> >
> > Does anyone have working code to achieve this?[/color]
>
> You could probably use exec and the linux "find" command to do this.
>
> Or, you could make a recursive function that reads files of a directory using
> opendir, readdir, closedir and compares the filename to the one requested using
> preg_match. If it encounters a directory (is_dir) you could call the same
> function to traverse it. Caution: be careful not to traverse "..". Also, make
> sure that the user can't steal files from outside the download directory
>
>
http://www.acme.com/download/find.php?file=/etc/passwd
> or
>
http://www.acme.com/download/find.ph...ris_hilton.mov
>
> This is actually a pretty easy function to write.[/color]
Oh, I forgot to mention that this function could return more than one result or
it could just return the first instance of the filename. You have to consider
how you want it to handle that. For that matter, the linux 'find' command could
return more than one result as well.
Regards,
Shawn
--
Shawn Wilson
shawn@glassgiant.com http://www.glassgiant.com
I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.