Page 1 of 1
file download script does not work
Posted: Sun Sep 04, 2005 7:55 am
by raghavan20
can anybody help me with this script?
Code: Select all
if (isset($_GET["file"])){
$size = filesize($_GET["file"]);
$file = $_GET["file"];
header("Content-type: text/plain");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=$file");
include($file);
}
Posted: Sun Sep 04, 2005 8:36 am
by feyd
don't use
include(),
readfile() is often best for this. Try placing double quotes around the filename in the disposition line.
Posted: Sun Sep 04, 2005 9:15 am
by raghavan20
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.php"); // filename is the name you want to store the file
//as.It can also be any other name
include 'test.php'; // this is the file that you want to download
?>
this is a static script which works fine....then why should not the earlier one work???
Posted: Sun Sep 04, 2005 9:24 am
by feyd
that wouldn't work fine if any of the contents of test.php are in fact php.

Posted: Sun Sep 04, 2005 9:46 am
by raghavan20
When I used the static script to download the test.php, all the php code has been cut off and the html code was intact.
http://raghavan.100webcustomers.com/download.php
why it can't read the php content? what do I have to do with content type to download a php file???
first of all, wots the logic behind this code....

Posted: Sun Sep 04, 2005 12:26 pm
by feyd
as I said before, use readfile(). Include() asks php to parse the file. readfile() opens and outputs the file to the client, no processing via php.