PDA

View Full Version : downloading php files as xxx.php


Ökii
10-17-2002, 05:16 PM
Currently my download script gets the .php files to the client, just happens to rename them all to download.txt rather than script.php - is there a way round that?

current syntax basics

$fname = '/home/etc/devsys/downloads/'.$fname;
if(false!==$fp=@fopen($fname,"rb"))
{
$filedown=@fread($fp,filesize ($fname));
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($fname));
header("Content-Disposition: attachment; filename=$fname");
header("Content-Transfer-Encoding: ascii");
echo $filedown;
}

which would be called as download.php?fname=myfile.php

I have tried content-type: application/force-download and text/plain as well - neither of which helped.

Anyone got any clever hints and tricks?

Ökii
10-17-2002, 07:27 PM
:doh:

As it is pretty hard to save a file as /folder/folder/folder/file.php the client machine ignores the suggested filename and uses download instead.

Basically I had to assure that the line

header("Content-Disposition: attachment; filename=".$fname);

referenced a variable $fname that contained no / characters for the files in subfolders of /downloads/

Am none too sure that the content-type header does much - am now using application/x-httpd-php which seems to work ok for IE/Moz modern