Re: Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ? [message #184034 is a reply to message #184031] |
Tue, 03 December 2013 13:15 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 12/3/2013 5:09 AM, The Natural Philosopher wrote:
> On 03/12/13 03:10, zhangfj(at)gmail(dot)com wrote:
>> Thank you for your informative reply.
>>
>> Briefly, my problem is that I can't download the file by programming.
>> I want to change "ABC" in the URL to download files automatically from
>> one site.
>>
>
> You need to have a link top a PHP program that reads the file, then sets
> up headers top tell the browser that it is not (to be understood to be)
> an HTML: page, but a file download, and then sends the file.
>
> so if your program was say -getfile.php and the file was 'rubbish.html'
>
> <?php
> header("Content-Disposition: attachment; filename=\"rubbish.html\"");
> header("Content-Type: text/plain");
> $data=file_get_contents("rubbish.html");
> echo($data);
>
> and that's it. No closing ?> should be used so there is no danger of
> setting characters NOT in the file itself - the script exits still in
> 'php mode'
>
> in your main page use
>
> <a href="getfile.php">Download the file here</a>
>
> Setting the content-disposition to 'attachment' strongly suggests to the
> browser that the contents should not be displayed as HTML but should be
> downloaded instead. However this behaviour is never 100% guaranteed.
>
> instead of a local filename you can use a URL as well, if you are trying
> to 'scrape' another website.
>
> curl() will give you more control if you need it than
> file_get_contents() for that.
>
> http://us1.php.net/manual/en/curl.examples-basic.php
>
>
Completely off the mark, as usual.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|