#36734 [Bgs]: fileopen through header
ID: 36734
User updated by: tgal at rdslink dot ro
Reported By: tgal at rdslink dot ro
Status: Bogus
Bug Type: HTTP related
Operating System: WindowsXP
PHP Version: 4.4.2
New Comment:
I think, this is a bug. But not the header() functions, it is a bug of
readfile() function.I tested it over and over, no error is reported,
not even the die() stops it, after that I've changed the readfile()
with echo file_get_contents() and works just perfectly. I tried to
compare the to results and they don't match, readfile() doesn't get all
the data and get's it wrong too.
Previous Comments:
------------------------------------------------------------------------
[2006-03-14 11:14:36] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2006-03-14 11:10:26] tgal at rdslink dot ro
Description:
------------
Under php-4.3.10 this method works just fine. But with php-4.4.1 and
php-4.4.2 the application crashes(mostly MS Word, because I try to open
rtf documents and this is the default application).
The script uses header function to get the document from server.
Reproduce code:
---------------
to get the file:
<a href="fileopen.php?folder=subfolder&filename=file.rtf">file.rtf</a>
fileopen.php:
<?
if(!isset($_GET["folder"])) $_GET["folder"]=NULL;
if(!isset($_GET["subfolder"])) $_GET["subfolder"]=NULL;
if(!isset($_GET["id"])) $_GET["id"]=NULL;
if(!isset($_GET["filename"])) $_GET["filename"]=NULL;
if($_GET["folder"]=="somatie")
{
$name="../".$_GET["folder"]."/".$_GET["filename"];
}
else
{
if($_GET["subfolder"]!=NULL)
$name="../".$_GET["folder"]."/".$_GET["subfolder"]."/".$_GET["id"].str_replace("*","&",$_GET["filename"]);
else
$name="../".$_GET["folder"]."/".$_GET["id"].str_replace("*","&",$_GET["filename"]);
}
$file_extension=strtolower(substr(strrchr($_GET["filename"],"."),1));
switch($file_extension)
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "csv":
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "mp3": $ctype="audio/mpeg"; break;
case "wav": $ctype="audio/x-wav"; break;
case "mpeg":
case "mpg":
case "mpe": $ctype="video/mpeg"; break;
case "mov": $ctype="video/quicktime"; break;
case "avi": $ctype="video/x-msvideo"; break;
//The following are for extensions that shouldn't be downloaded
(sensitive stuff, like php files)
case "php":
case "htm":
case "html":
case "txt": die("<b>Cannot be used for ". $file_extension ."
files!</b>"); break;
default: $ctype="application/force-download";
}
// send the right headers
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate,
post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: $ctype");
header('Content-Disposition: attachment;
filename="'.$_GET["filename"].'";');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($name));
// dump the picture and stop the script
@readfile($name);
exit;
?>
Expected result:
----------------
The file should be opened with the default application.
Actual result:
--------------
Default application crashes.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36734&edit=1
Thread (3 messages)