Forum Moderators: coopster
Firstly, I'm inside a script using PHP sessions (according to the fpasshtru manual page this can make a difference).
I want to have people click on a download link. When they do, I execute a bit of code, then send them the file.
Firstly, I tried using the Location: header. This worked fine in IE, but Mozilla just displayed the file (think I probably have a nextraneous space or line reuturn somewhere - haven't been able to find it - my script is in multiple files).
I have now got it so I can download the file, but the file is given the name of the PHP script, which I don't want. I want the file to have it's original filename.
Here's my code so far:
$filename = 'files/' . $data_upload['filename']; if (file_exists ($filename)) {
$FILECMD = '/usr/bin/file';
$contentType = '';
$fp = popen("$FILECMD -bin $filename", 'r');
if (!$fp) {
$contentType='application/octet-stream';
} else {
while($string=fgets($fp, 1024)) $contentType .= $string;
pclose($fp);
}
if (strpos ($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')) {
// IE cannot download from sessions without a cache
header('Cache-Control: public');
// Fix problems with multiple .'s in filenames
$fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
}
header("Content-type: $contentType");
header("Content-Disposition:inline; filename=\"".$file."\"");
header("Content-length:".(string)(filesize($filename)));
$fd=fopen($filename,'rb');
while(!feof ($fd)) {
print fread($fd, 4096);
}
fclose($fd);
} else {
print "File Not Found";
}
Please tell me this can be done!
Allen
PS. Someone should really fix these forums to preserve code indenting o_O