How to download file through URL using PHP
Moderator: General Moderators
How to download file through URL using PHP
How to use PHP to download a file/picture by given a URL. And save the downloaded file to disk.
Thanks.
Thanks.
try the manual, it is always a good bet.
file_get_contents does that
NOTE: I'm faster than lightning

file_get_contents does that
NOTE: I'm faster than lightning
... well, I do believe I'm a bit older now than I was when I first posted this postif you were faster then light, techniqally (dont know how to spell that) you would be moving through time...
Last edited by Syranide on Wed Jun 22, 2005 4:10 am, edited 2 times in total.
-
method_man
- Forum Contributor
- Posts: 257
- Joined: Sat Mar 19, 2005 1:38 am
-
method_man
- Forum Contributor
- Posts: 257
- Joined: Sat Mar 19, 2005 1:38 am
File download
To download a file you will have to specify the header information in your script.
It will be like this :
Yenjoyy ! 
A s m i e
It will be like this :
Code: Select all
header("Content-type: text/plain"); //here you will have to mention the file type
header("Content-Length: 1024"); // this is the filesize
header("Content-Disposition: attachment; filename=test.txt"); // filename is the name you want to store the file as.It can also be any other name
include 'test.txt'; // this is the file that you want to downloadA s m i e
can fread do this:
<?php
// get contents of a file into a string
$filename = "http://www.usa.com/index.html";
$handle = fopen($filename, "r");
...
Re: File download
I just want to down load a file using PHP.asmie wrote:To download a file you will have to specify the header information in your script.
It will be like this :
Yenjoyy !Code: Select all
header("Content-type: text/plain"); //here you will have to mention the file type header("Content-Length: 1024"); // this is the filesize header("Content-Disposition: attachment; filename=test.txt"); // filename is the name you want to store the file as.It can also be any other name include 'test.txt'; // this is the file that you want to download
A s m i e
Using php to retrieve a file by given a url:http://www.usa.com/index.html,
save the index.html to disk.
-
method_man
- Forum Contributor
- Posts: 257
- Joined: Sat Mar 19, 2005 1:38 am
Do you want an end user to be able to download files from your site ?
Something like downloading a mail attachment that we can download to our disk??
If yes then :
To download using an url you will have to specify like this :
http://www.usa.com/index.php
In index.php u can paste the code i had given in my previous post.
If the file you want to download is varying then you will have to change the code in the header.
Instead of
include 'test.txt';
You have to write the filename that u want to download.
A s m i e
Something like downloading a mail attachment that we can download to our disk??
If yes then :
To download using an url you will have to specify like this :
http://www.usa.com/index.php
In index.php u can paste the code i had given in my previous post.
If the file you want to download is varying then you will have to change the code in the header.
Instead of
include 'test.txt';
You have to write the filename that u want to download.
A s m i e