rfresh
07-20-2009, 06:19 AM
Is there a way I can download a file to my local PC using a File Save As dialog but which grabs the file using a URL?
Thanks...
Thanks...
|
||||
Save As from a URL?rfresh 07-20-2009, 06:19 AM Is there a way I can download a file to my local PC using a File Save As dialog but which grabs the file using a URL? Thanks... DaiWelsh 07-20-2009, 10:33 AM Unclear on the question - File/Save As from what - your browser? some other application? Browser "Save As" is already saving it from whatever URL the browser is pointed at, so again, unclear what exactly you are trying to achieve that you can't by default? rfresh 07-20-2009, 02:51 PM Yes, from a browser I want to have a File Save As dialog popup and I want to pull the file via a URL and save it to my local PC. MattF 07-20-2009, 02:59 PM The question still makes no sense. If you point your browser to the URI of a file, it will already prompt you to save/open the file. If you want to achieve something else, explain exactly what you mean/want. rfresh 07-20-2009, 03:30 PM >If you point your browser to the URI of a file, it will already prompt you to >save/open the file. How do you do this in PHP? What function? MattF 07-20-2009, 03:35 PM >If you point your browser to the URI of a file, it will already prompt you to >save/open the file. How do you do this in PHP? What function? Do what? If you're going to speak in riddles..... Scriptet 07-20-2009, 03:37 PM I think the header() (http://uk.php.net/manual/en/function.header.php) function does this for you MattF 07-20-2009, 03:44 PM I think the header() (http://uk.php.net/manual/en/function.header.php) function does this for you If he's wanting to serve a file from a script link, it does. :) The Location, Content-type and Content-Disposition parts are the relevant ones. Arnaud 07-20-2009, 03:45 PM What is the goal? To hide the URL of the file you want users to download? rfresh 07-20-2009, 03:48 PM What is the goal? To hide the URL of the file you want users to download? The goal is to pull a file from a different server than the php script is running on and then save it to my local PC. Arnaud 07-20-2009, 03:52 PM You are good at giving us a very little more info at each post... I don't see what special you need... what kind of file are you trying to save? What extension? If I have server 1 that is www.mysite.com and server 2 that is www.myothersite.com what is the problem to make a link such as the below one? <a href="http://www.myothersite.com/file.txt">Download</a> Of course it depends what kind of file you are trying to download... rfresh 07-20-2009, 03:55 PM It's a .txt file. I will try your code example. Thanks... Arnaud 07-20-2009, 03:57 PM Well... this is not 'code'... This is a simple HTML hyperlink... rfresh 07-20-2009, 03:58 PM You are good at giving us a very little more info at each post... I don't see what special you need... what kind of file are you trying to save? What extension? If I have server 1 that is www.mysite.com and server 2 that is www.myothersite.com what is the problem to make a link such as the below one? <a href="http://www.myothersite.com/file.txt">Download</a> Of course it depends what kind of file you are trying to download... Your example code just pulls the .txt content into the browser, there is no Save As dialog. As MattF stated, I think I need to use header() MattF 07-20-2009, 04:49 PM Your example code just pulls the .txt content into the browser, there is no Save As dialog. As MattF stated, I think I need to use header() You'll need to use a placeholder link inplace of the direct link, which calls your script and processes the request, for this method to work. rfresh 07-20-2009, 05:12 PM Thanks everyone for your help - I think I have enough information now to get this to work. MattF 07-20-2009, 05:21 PM Just one other header that may be worthwhile using: header('Content-Disposition: inline; filename="[filename here]"'); That should make sure that you always get prompted to open/save. Some formats may still be opened directly in the browser unless you use that header also. sea4me 07-20-2009, 05:28 PM Here is the correct way: <?php // Define the path to file $file = 'test.txt'; if(!file) { // File doesn't exist, output error die('file not found'); } else { // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); // Read the file from disk readfile($file); } ?> for a force download (what you want) :) MattF 07-20-2009, 05:49 PM Does the encoding:binary line achieve the same as the disposition:inline method then? I seem to recall PDF's always causing grief if I tried disposition:attachment alone. I never tried the binary line though, if I remember correctly. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum