Hi. Have a little problem. Have written a script to download a file from anywhere on a server (I know, big security risk but it doesn't matter just yet) and have run into a problem. The code I am using looks something like this:
Link to file, in document files.php
<a href=files.php?download=helloworld.txt&path=/home/test>
When the user clicks this;
if (isset($download))
{
download_file($file,$path);
}
function download_file($file,$path)
{
$absfile = $path . "/" . $file;
list ($na, $ext) = explode ('.', $file);
//use function to find mime type
$mimetype = mime_lookup($ext);
//download file
$download = fopen($absfile,"r");
$buf = '';
while(!feof($download))
$buf .= (fread($download,4096));
$header = "Content-Disposition: attachment;filename=$file \n Content-type: $mimetype \n Content-length: $size \n";
header ($header);
echo $buf;
}
However, whenever a user clicks on the link, a dialog comes up saying something like 'test'. If you click 'Open' rather than 'Save', another dialog comes up and it all works fine. But why that first dialog?
Any help gratefully received.