<?php
if(isset($_GET['down']) AND $_GET['down'] == "ok")
{
header('Content-Type:application/txt\n');
header("Content-Length:2000\n");
header('Content-Disposition: inline; filename="http://localhost/abc.txt"');
readfile("http://localhost/abc.txt");
}
?>
<a href="http://localhost/download.php?down=ok">download this file</a>
Downloading file in phpHow to download file in php,plz check my code
Page 1 of 1
4 Replies - 853 Views - Last Post: 03 January 2010 - 12:48 PM
#1
Downloading file in php
Posted 03 January 2010 - 03:25 AM
Replies To: Downloading file in php
#2
Re: Downloading file in php
Posted 03 January 2010 - 03:39 AM
You can only send the header once.
Why are you having php handle the download rather than just supplying an href?
Why are you having php handle the download rather than just supplying an href?
#3
Re: Downloading file in php
Posted 03 January 2010 - 04:23 AM
Just use file_get_contents() to get the file from the server, as long as it is defined in your php.ini that you can do that.
#4
Re: Downloading file in php
Posted 03 January 2010 - 04:38 AM
if(isset($_GET['down'])
{
JamesBrown = true;
}
#5
Re: Downloading file in php
Posted 03 January 2010 - 12:48 PM
<?php
if(isset($_GET['down']) && $_GET['down'] == "ok")
{
header("Content-Type:application/txt");
header("Content-Length:2000");
header('Content-Disposition: attachment; filename="abc.txt"');
readfile("abc.txt");
exit;
}
?>
<a href="http://localhost/download.php?down=ok">download this file</a>
Try that out, assuming that this download file is in the same directory as the abc.txt file. Also note that you don't need to add line breaks in headers, and that you can not do carriage returns (the \r\n) in single quotes, in PHP single quotes means a literal string, so when you output that string, it looks just like it does in the source, and also, when using readfile, you shouldn't use a URL to the file, but a path to the file.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|