FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ? [message #184031 is a reply to message #184028] Tue, 03 December 2013 10:09 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
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


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: foreach as list
Next Topic: illegal offset problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Oct 28 13:19:53 GMT 2024

Total time taken to generate the page: 0.04264 seconds