note 18445 added to function.fpassthru
| From: | mirko at mcaserta dot com | Date: | Wed, 23 Jan 2002 10:07:14 +0000 |
| Subject: | note 18445 added to function.fpassthru | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-25736@lists.php.net to get a copy of this message | ||
Update to the above. This also sets the correct mime type for the file you're sending.
It's a small hack since it relies on the "file" system command but it should work
well.
<?
// full path to the file command
$FILECMD='/usr/bin/file';
// directory where the file resides
$fileDir='/home/mcaserta';
// full file name
$fileName='test.sh';
// END CONFIG
$completeFilePath=$fileDir.'/'.$fileName;
$fp=popen("$FILECMD -bin $completeFilePath", 'r');
if (! $fp) $contentType='application/octet-stream';
else {
while($string=fgets($fp, 1024)) $contentType .= $string;
pclose($fp);
}
header('Content-type: '.($contentType));
header('Content-Disposition: inline; filename="'.($fileName).'"');
header('Content-length: '.(string)(filesize($completeFilePath)));
$fd=fopen($completeFilePath,'r');
fpassthru($fd);
?>
--
http://www.php.net/manual/en/function.fpassthru.php
http://master.php.net/manage/user-notes.php?action=edit+18445
http://master.php.net/manage/user-notes.php?action=delete+18445
http://master.php.net/manage/user-notes.php?action=reject+18445