if ($rights&1) //if user has right to read file
{
$fileextension = strtolower( substr(strrchr($file, "."), 1) );
//if the file has an extension, which should be included (i.e. php, htm, ...)
if (in_array($fileextension, $_SYSTEM["extensions_include"]))
{
include($file);
}
else
{
switch ($fileextension)
{
case "pdf": $ctype="application/pdf"; break;
case "zip": $ctype="application/zip"; break;
case "rar": $ctype="application/x-rar-compressed"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "txt": $ctype="text/plain"; break;
case "gif": $ctype="image/gif"; break;
case "bmp": $ctype="image/bmp"; break;
case "png": $ctype="image/png"; break;
case "jpeg": $ctype="image/jpeg"; break;
case "jpg": $ctype="image/jpeg"; break;
case "tif": $ctype="image/tiff"; break;
case "tiff": $ctype="image/tiff"; break;
default: $ctype="application/octet-stream"; break;
}
header('Content-Type: '.$ctype);
header('Content-Length: '.@filesize($file) );
header("Content-Transfer-Encoding: binary");
@readfile($file);
}
}
else //user has no right to read file. show login form.
{
//...
}