On my site I use these two blocks of code to open protected files. I can open the files fine, and so can plenty of others. The problem is that at least one person complained that they couldn't open the file. This is what they had to say:


It opened Adobe, then an
Adobe Reader window opened that stated "There was an error opening this
document.  This file cannot be found."

So that must mean that the streamfile($file) function (see below) did not return false, 
otherwise the message would have been "file was not found.  please send [EMAIL 
PROTECTED]"

Does someone know what's going on here?  Since I am not experincing this problem first 
handed, I really have no clue.  Also, shouldn't this person get prompted if he wants 
to save it or open it with Adobe Acrobat?

Best Regards,

Scott Taylor


<?php

include("subscriber_functions.php");

session_name("miningstocks_subscribers");
session_set_cookie_params(TIMEOUT_SUBSCRIBERS);
session_start();


if (isset($_SESSION['email']))
{
$file = $_SERVER['DOCUMENT_ROOT'] . "/subscribers/archive/" . $_GET['file'];
if (streamfile($file) == FALSE)
{
include ($_SERVER['DOCUMENT_ROOT'] . "/nonindex_header.shtml");
?>
<div id="headline"><h1>File not found</h1></div>
<div id="main"><p>The File was not found. Please send <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> an email with error code 1000 - file not found.</p></div>
<?
include ($_SERVER['DOCUMENT_ROOT'] . "/footer.shtml");
}
}
else
{
header("Location: http://www.miningstocks.com/error_docs2/problem_browser.php";);
exit();
}
?>


-------------------------------------------------------------------------------

in subscriber_functions.php:


// will return FALSE if the file is not found
// will not return anything if the file is found because the headers should
// have already been sent.
function streamfile($file)
{
if (file_exists($file))
{
//find the extension. hopefully there are no directories with periods in them!
$extension = stristr($_POST['file'], ".");
$extension = strtolower($extension); //now it streams the file
if ($extension == ".php")
{
include($file);
}
else if ($extension == ".html" || $extension == ".htm" || $extension == ".shtml")
{
include($file);
}
else
{


// a switch would be perfect here,
// but it just didn't work last time...it was always
// taking the 'default:' case
if ($extension == ".doc"){$type = "application/msword";}
else if ($extension == ".pdf"){$type = "application/pdf";}
else if ($extension == ".exe"){$type = "application/octet-stream";}
else if ($extension == ".ppt"){$type = "application/vnd.ms-powerpoint";}
else if ($extension == ".xls"){$type = "application/vnd.ms-excel";}
else if ($extension == ".xml"){$type = "text/xml";}
else if ($extension == ".zip"){$type = "application/zip";}
else if ($extension == ".txt"){$type = "text/plain";}
else {
$type="application/octet-stream";
}


header("Content-Type: " . $type);
header("Accept-Ranges: bytes");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=".basename($file).";"); //readfile($file); $fp = fopen($file, 'rb');
$buffer = fread($fp, filesize($file));
fclose($fp);
print $buffer;
exit(); } }
else
{
return FALSE;
}
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to