Export file to local desktop (can select folder/directory)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
antoniobanjeras
Forum Newbie
Posts: 10
Joined: Mon Aug 04, 2008 11:13 pm

Export file to local desktop (can select folder/directory)

Post by antoniobanjeras »

Hi

Is there a php command to export (or copy) file from server (my server running linux) to local desktop or user can select folder from local computer.

thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Export file to local desktop (can select folder/directory)

Post by requinix »

It's called a "download".

Code: Select all

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
Create a new page - this will be specifically for letting users download stuff. Use $_GET or $_POST or whatever and figure out what file to download. Make sure they're allowed to download it!
Then put that code in the script (remember to set $filename to whatever you want the name of the downloaded file to be) and print out the file contents, perhaps using readfile. User will get a save/open dialog and they can do what they want.

You cannot force them to download something to a specific place. The best you can do is what I've said: give them the choice of where to save the file, if they want to download it at all.
antoniobanjeras
Forum Newbie
Posts: 10
Joined: Mon Aug 04, 2008 11:13 pm

Re: Export file to local desktop (can select folder/directory)

Post by antoniobanjeras »

tasairis, thanks.

exactly the stuff i've been looking for.
Post Reply