download files from a website

Hey guys,

Is it possible to download files from a website using PHP ?? If yes,
then how ??
Also, how do I write data to a file in php ??

If these functions can be done in PHP then please let me know how I
can do it. Also, where can I see all the functions of PHP ?? Is there
something like an API that I can look at ?

Please reply soon.

Thank you,

Vivek
vivekmahanta [ Mo, 05 Februar 2007 04:20 ] [ ID #1619378 ]

Re: download files from a website

Hi Vivek ,

Downloading file from web page using PHP , see below.
For write data to file , look up the file function in php manual, it
have some examples.

Thanks

$filename = 'Your file name';
// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// use the Content-Disposition header to supply a recommended filename
and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=" .
basename($filename) . ";");

/*
The Content-transfer-encoding header should be binary, since the file
will be read
directly from the disk and the raw bytes passed to the downloading
computer.
The Content-length header is useful to set for downloads. The browser
will be able to
show a progress meter as a file downloads. The content-lenght can be
determines by
filesize function returns the size of a file.
*/

header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filename));

readfile("$filename");
exit();




On Feb 5, 11:20 am, "vivekmaha... [at] gmail.com" <vivekmaha... [at] gmail.com>
wrote:
> Hey guys,
>
> Is it possible to download files from a website using PHP ?? If yes,
> then how ??
> Also, how do I write data to a file in php ??
>
> If these functions can be done in PHP then please let me know how I
> can do it. Also, where can I see all the functions of PHP ?? Is there
> something like an API that I can look at ?
>
> Please reply soon.
>
> Thank you,
>
> Vivek
weetat.yeo [ Mo, 05 Februar 2007 08:07 ] [ ID #1619381 ]

Re: download files from a website

On Feb 5, 2:07 am, "weetat" <weetat.... [at] gmail.com> wrote:
> Hi Vivek ,
>
> Downloading file from web page using PHP , see below.
> For write data to file , look up the file function in php manual, it
> have some examples.
>
> Thanks
>
> $filename = 'Your file name';
> // fix for IE catching or PHP bug issue
> header("Pragma: public");
> header("Expires: 0"); // set expiration time
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> // browser must download file from server instead of cache
> // force download dialog
> header("Content-Type: application/force-download");
> header("Content-Type: application/octet-stream");
> header("Content-Type: application/download");
> // use the Content-Disposition header to supply a recommended filename
> and
> // force the browser to display the save dialog.
> header("Content-Disposition: attachment; filename=" .
> basename($filename) . ";");
>
> /*
> The Content-transfer-encoding header should be binary, since the file
> will be read
> directly from the disk and the raw bytes passed to the downloading
> computer.
> The Content-length header is useful to set for downloads. The browser
> will be able to
> show a progress meter as a file downloads. The content-lenght can be
> determines by
> filesize function returns the size of a file.
> */
>
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: " . filesize($filename));
>
> readfile("$filename");
> exit();
>
> On Feb 5, 11:20 am, "vivekmaha... [at] gmail.com" <vivekmaha... [at] gmail.com>
> wrote:
>
>
>
> > Hey guys,
>
> > Is it possible to download files from a website using PHP ?? If yes,
> > then how ??
> > Also, how do I write data to a file in php ??
>
> > If these functions can be done in PHP then please let me know how I
> > can do it. Also, where can I see all the functions of PHP ?? Is there
> > something like an API that I can look at ?
>
> > Please reply soon.
>
> > Thank you,
>
> > Vivek- Hide quoted text -
>
> - Show quoted text -

I dont know if I explained myself properly. Actually, suppose there is
a file located on a URL like www.yahoo.com/gogo.txt and I want to
download gogo.txt from the yahoo website using php. How do I specify
that in PHP ?? Please reply soon.

Thank you,

Vivek
vivekmahanta [ Mo, 05 Februar 2007 22:37 ] [ ID #1619392 ]

Re: download files from a website

vivekmahanta [at] gmail.com wrote:

> I dont know if I explained myself properly. Actually, suppose there is
> a file located on a URL like www.yahoo.com/gogo.txt and I want to
> download gogo.txt from the yahoo website using php. How do I specify
> that in PHP ??

You can start with reading the following page,
http://www.php.net/manual/en/function.fopen.php
it will give the information you need on downloading a remote file and saving
a file. When working with ftp/http protocols, you will need a wrapper that
allows you to use those protocols with fopen().

--

//Aho
Shion [ Mo, 05 Februar 2007 23:20 ] [ ID #1619393 ]

Re: download files from a website

quick and dirty code :
<?php
$fp = fopen ("http://www.abc.com/abc.txt" ,"r");
$data = fread ($fp, 2048);
fclose ($fp);

$fp = fopen ("/home/data/abc.txt", "w");
fwrite ($fp, $data);
fclose ($f);
?>

http://www.mastervb.net/phpbooks/

On Feb 6, 5:20 am, "J.O. Aho" <u... [at] example.net> wrote:
> vivekmaha... [at] gmail.com wrote:
> > I dont know if I explained myself properly. Actually, suppose there is
> > a file located on a URL likewww.yahoo.com/gogo.txtand I want to
> > download gogo.txt from the yahoo website using php. How do I specify
> > that in PHP ??
>
> You can start with reading the following page,http://www.php.net/manual/en/function.fopen.php
> it will give the information you need on downloading a remote file and saving
> a file. When working with ftp/http protocols, you will need a wrapper that
> allows you to use those protocols with fopen().
>
> --
>
> //Aho
lorento [ Di, 06 Februar 2007 06:00 ] [ ID #1620653 ]
PHP » alt.php » download files from a website

Vorheriges Thema: displaying count
Nächstes Thema: PHP help with Control Structure