472,952 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

force-downloaded report file flooded with HTML by mistake

[PHP]
class ReportGenerator {

function ReportGenerator() {}

/**

* Generate the HTTP headers necessary for this file type. Can be
called statically

*

* @access public

* @param mixed $filename
* @see file_get_contents
* @see actual_path

*/

function &generateHTTPHeaders($filename) { // STATIC VOID METHOD

if (!preg_match('/.+\.[a-zA-Z0-9\-_]+$/i', $filename)) die("Filename:
\"$filename\" must have an extension");
$ext = substr($filename, strrpos($filename, '.') + 1,
strlen($filename));

switch (strtolower(trim($ext))) {

case 'pdf':

$ctype = 'application/pdf';

break;

case 'exe':

$ctype = 'application/octet-stream';

break;

case 'zip':

$ctype = 'appliation/zip';

break;

case 'doc':

$ctype = 'application/msword';

break;

case 'xls':

$ctype = 'application/vnd.ms-excel';

break;

case 'csv':

$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 'jpg':

$ctype = 'image/jpg';

break;

case 'jpeg':

$ctype = 'image/jpg';

break;

default:

$ctype = 'application/force-download';

break;

}

header('Pragma: public');

header('Expires: 0');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header("Content-Type: $ctype");

$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);

if ((is_integer(strpos($user_agent, 'msie'))) &&
(is_integer(strpos($user_agent, 'win')))) {

header('Content-Disposition: filename=' .
basename(actual_path($filename)) . ';');

} else {

header('Content-Disposition: inline; filename=' .
basename(actual_path($filename)) . ';');

}

header('Content-Transfer-Encoding: binary');

header('Content-Length: ' . @filesize(actual_path($filename)));

if (function_exists('file_get_contents')) {

echo @file_get_contents(actual_path($filename));

} else {

@readfile(actual_path($filename));

}

}
}
[/PHP]

The class method generateHTTPHeaders() can be called statically to
force-download a file (Excel, CSV, PDF, etc.) per customer requirement.
However, upon attempting to do so:

[PHP]
// REAL IMPORTANT!!! CHMOD OR THE WORLD CAN SEE YOUR REPORTS!!!!!!!
if ($this->isSuccessful) @chmod(0770,
actual_path($newReportFileName)); // CHANGE PERMISSIONS (IF IN UNIX)
TO PREVENT WORLD FROM ACCESSING FILE
if ($this->isSuccessful)
ReportGenerator::generateHTTPHeaders($newReportFil eName); // THIS
CAUSES THE FORCED DOWNLOAD
@unlink(actual_path($newReportFileName)); // FILE HAS BEEN
FORCE-DOWNLOADED AND IS NO LONGER NEEDED ON SERVER
@unlink(actual_path($reportFileName)); // REMOVE THE
TEMPORARY FILE AS WELL, PROVIDED IT EXISTS AND/OR YOU CAN
if ($this->isSuccessful) exit();
[/PHP]

The force-downloaded file you get is completely flooded with HTML,
particularly the HTML of the page itself! I do not understand how this
is possible, particularly since I ran careful traces up until the
headers are spawned, and the resulting file contents are legitimate
report data (no HTML) up until you generate the headers at the end of
the method, then suddenly HTML pours in like a breached levee!

Any ideas? This is as much code as I am able to display that would be
relevant to the problem, I'm afraid.

Thanx
Phil

Apr 20 '06 #1
2 2213
comp.lang.php wrote:
[PHP]
<code snipped>

The force-downloaded file you get is completely flooded with HTML,
particularly the HTML of the page itself! I do not understand how this
is possible, particularly since I ran careful traces up until the
headers are spawned, and the resulting file contents are legitimate
report data (no HTML) up until you generate the headers at the end of
the method, then suddenly HTML pours in like a breached levee!

Any ideas? This is as much code as I am able to display that would be
relevant to the problem, I'm afraid.

Thanx
Phil


Phil,

You're telling us you're getting additional stuff out, but you aren't showing
use all the code involved. Sorry, we don't have crystal balls. It would be
virtually impossible to answer your question without all the code involved.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 20 '06 #2

Jerry Stuckle wrote:
comp.lang.php wrote:
[PHP]
<code snipped>

The force-downloaded file you get is completely flooded with HTML,
particularly the HTML of the page itself! I do not understand how this
is possible, particularly since I ran careful traces up until the
headers are spawned, and the resulting file contents are legitimate
report data (no HTML) up until you generate the headers at the end of
the method, then suddenly HTML pours in like a breached levee!

Any ideas? This is as much code as I am able to display that would be
relevant to the problem, I'm afraid.

Thanx
Phil


Phil,

You're telling us you're getting additional stuff out, but you aren't showing
use all the code involved. Sorry, we don't have crystal balls. It would be
virtually impossible to answer your question without all the code involved.


Sorry there was no way I could display any more code since it would
involve about 5 scripts @ 3000 lines each to show you all of the code
involved. And since it's government-proprietary in this case, I can't
do that.

However, it works now.. turns out that it misbehaves if you use
Konqueror, otherwise, it's just fine in IE and Firefox (both Win and
Linux)

Phil

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Apr 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

133
by: Philipp Lenssen | last post by:
Why is there no standardized and well-working way for a web-page to offer the font for download/embed it, in order to be displayed on the page? No matter what you think of the preferred font of a...
2
by: Raquel | last post by:
FORCE APPLICATION command is valid only at the 'instance' level. Why is this so? An instance may contain many databases. So, what command do I give if I want to force applications from a particular...
2
by: Tony Do | last post by:
I have the backup command BACKUP DATABASE NEST TO C:\\databases WITH 2 BUFFERS BUFFER 1024 $ How do I force all the user to disconnect? before running the above command
3
by: Arran Pearce | last post by:
Hi, If i have a abstract class (e.g. Class1) and then i make Class2 which inherits from Class1. I have a method in Class1 which i want to force Class2 to run at some point. Is there a way i...
4
by: Tom | last post by:
Does anyone know how ot force a postback in the codebehind? Thanks Tom
3
by: buht | last post by:
Hello Everyone, Fairly new to c# here and have a question regarding scrollbars, particularly a vertical scrollbar. It looks like my options are restricted for the textbox scrollbars being...
8
by: Keith H | last post by:
I'm looking for a way to force the user to re-authenticate with their Windows username/password/domain after clicking the submit button on an ASP.NET page. This is for an internal application. ...
1
by: Mark A | last post by:
DB2 ESE 8.2.3 (FP10) for Linux We are experiencing a connection hang of 10 - 15 minutes in the following HADR and automatic client reroute scenario: 01 server is primary database 02 server is...
2
by: cottonj | last post by:
is there anyway to force an event, like mouseover? I have a page that loads, and due to some complex js code (not mine) it fails to write labels to tabs until the user does a mouseover on the...
0
by: Thommy M. | last post by:
I thought the below would do a force installation of a CPAN module on Solaris 10 x86 but it still says it won't install without force. What is the command syntax??? perl -MCPAN -e'force...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.