tags:

views:

363

answers:

2

I am trying to make a application in which admin will be able to see the files from particular folder(predefined) and should be able to download them one by one. The files will be stored on the server. Can someone guide me how to do this?

A: 

Check the file_get_contents function. It does what you need.

For instance:

<?php $file_content = file_get_contents ('ftp://mysite.com/file.txt'); ?>

Then you just need to write the content to the filesystem with file_put_contents or fwrite (as you prefer).

rogeriopvl
Won't work as it's not possible to get a file list of the directory using file_get_contents.
André Hoffmann
Yes i think the get file_get_contents will not work. I want to display the list of files and want to make them downloadable by the admin.
+1  A: 

Are you trying to get a list of files in a remote FTP server? If so, then you need either the ftp extension or use the Net-FTP2 extension from PEAR (it has sadly been abandoned, but you may be able to salvage some code from there)

As for serving a specific file that comes from a FTP server to a remote user, I would suggest the readfile function

readfile('ftp://server/file.txt');

Keep in mind, that you also need to add proper headers, like Content-Type, Content-Length, etc, the readfile manual page has some examples.

Anti Veeranna
I would like to explain my situation. There is folder say XXXX on the server. The XXXX folder gets updated(files are added to it automatically) once the user completes a set of questions. Now i want to design a application in which the admin will be able to see the names of the files and the will be able to download them one by them on the click of a button.Can u guide me and provide me a sample code, that will be great.
the folder is on the server.
So, start implementing it and ask if you hit problems.Are you sure there is any FTP involved here at all?
Anti Veeranna