Click to See Complete Forum and Search --> : PHP, download


rbermejo
10-18-2002, 07:52 PM
I have this to launch a browser download.
The problem is that the file being downloaded
is given as :scriptname.php
I just wanna chage the name to 0.csv



<?
$fileread = fopen ( '0.csv', "r");
$macrotoecho = fread ($fileread,1000000);
Header("Content-Type: application/x-octet-stream");
Header("Content-Disposition: attachment;
echo $macrotoecho;
?>


Thks

Fandelem
10-23-2002, 11:18 AM
Try:


if (strstr (getenv('HTTP_USER_AGENT'), 'Netscape')) {
$browser = "Netscape";

} else {
$browser = "IE";
}

$fp = fopen ( '0.csv', "r");
$file = fread ($fp,strlen('0.csv'));

// Download File
file_download($file, $browser);

/**
* Sends header & file info to client.
* File must exist with full path to grab filesize
* Otherwise, manipulate this function to just have the filesize passed in.
*/
function file_download($file, $browser) {

$size = filesize($file);

$filename = ereg_replace('[^-a-zA-Z0-9\.]', '_', $filename);

if ( $browser == "IE" ) {
header("Content-Type: application/download; name=$filename");
header("Content-Length: $size");
header("Content-Disposition: inline; filename=\"$filename\"");
} else if ( $browser == "Netscape" ) {
header("Content-Type: application/octet-stream; name=$filename");
header("Content-Length: $size");
header("Content-Disposition: filename=$filename");
}
header("Content-Transfer-Encoding: binary");

$fh = fopen("$file", "rb");
fpassthru($fh);
fclose($fh);


return;

}


this varies on browser i believe though, as to how it expects the header. unfortunately.


hth,

k.

rbermejo
10-23-2002, 12:38 PM
THnks it works !!