473,287 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Force download + Force redirect at the exact same time?

I have a form that when you click the "Generate Report" submit button,
it will force download a CSV file, required for this project.

On the very same page you also have a "Search" submit button, when you
press it it should generate search results in a new page.

However, when you click the "Generate Report" submit button, the moment
you try to THEN click the "Search" submit button, the "Search" submit
button NEVER goes to a new page but instead tries to force-download the
very same CSV file, as if the "Search" submit button literally becomes
the "Generate Report" submit button!

Is there a way using PHP and HTTP headers to force BOTH a download AND
a redirect literally at the exact same time? This is the only way I
can think of to stop this from happening, unless the user physically
reloads their page each time, which is not going to be acceptable by
the client.

[PHP]
class ActionPerformer extends DBActionPerformer {

var $id;

function ActionPerformer($id) {
$this->id = $id;
}

/**
* Generate a report
*
* @access protected
* @see change_first_order_flag
* @see actual_path
*/
function &report() { // STATIC VOID METHOD
global $scriptPath, $adminReportPath, $tempAdminReportPath;
$orderBy = ' upper(school_type_name) asc, upper(school_name) asc,
upper(student_last_name) asc, upper(student_first_name) asc,
upper(student_mi) asc ';

// BOOLEAN TO INDICATE IF A MOVE FROM A TEMP FOLDER TO THE ACTUAL
FOLDER WILL TAKE PLACE, ELSE, WILL REMAIN IN ACTUAL FOLDER
$willMoveReportFromTemp = ($tempAdminReportPath &&
strcmp(trim($adminReportPath), trim($tempAdminReportPath)) != 0);

// CHANGE "asc" TO "desc" AND VICE VERSA
if ($_REQUEST['willDesc']) $orderBy =
change_first_order_flag($orderBy);
// SUB OUT ALL CARRIAGE RETURNS AND LINE FEEDS
$orderBy = str_replace("\n", ' ', str_replace("\r", ' ',
htmlspecialchars($orderBy))); // EXTRA PROTECTION
$msg = "php -q \"" .
actual_path("$scriptPath/stored_procedures/get_student_group_resultset.php")
.. "\" \"ORDER BY $orderBy\" 'willExcludeCustomer' '' '' ''
'willGenerateReport'";

$reportFileName = exec($msg); // ERROR REDIRECTION HANDLED
BY PSEUDO-STORED PROCEDURE
if ($willMoveReportFromTemp) { // GENERATE RENAMED PATH +
FILENAME HERE FOR EFFICIENCY
$newReportFileName = preg_replace('/(^.*)' . str_replace('/', '\\/',
preg_quote($tempAdminReportPath)) . '(.*$)/', '$1' . $adminReportPath .
'$2', $reportFileName);
} else {
$newReportFileName = $reportFileName;
}

if (preg_match('/(error)|(errcode:?)/i', $reportFileName)) { //
ERROR ATTEMPTING TO TRY TO USE PSEUDO-STORED PROC TO SPAWN REPORT FILE
$this->isSuccessful = false;
$this->setErrorArray(array('action' => 'Unable to generate report: '
.. nl2br(htmlspecialchars($reportFileName)) . ': please contact
administrator'));
} else {
if ($willMoveReportFromTemp &&
@!copy(actual_path(realpath($reportFileName)),
actual_path($newReportFileName))) { // COPY FROM TEMP FOLDER IF
REQUIRED
list($copyKommand, $copyRedirect) =
@array_values($this->getKommandOSArray('copy'));
$msg = exec("$copyKommand \"" .
actual_path(realpath($reportFileName)) . '" "' .
actual_path($newReportFileName) . "\" $copyRedirect");
if ($msg || !is_file(actual_path($newReportFileName))) {
$errorMsg = "Unable to copy report from \"$reportFileName\" to
\"$newReportFileName\"";
if ($msg) $errorMsg .= ': "' . nl2br(htmlspecialchars($msg)) .
'"'; else echo ": No such file \"$newReportFileName\"";
$this->isSuccessful = false;
$this->setErrorArray(array('action' => $errorMsg));
}
}
// 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($reportFileNa me); // THIS CAUSES
THE FORCED DOWNLOAD
@unlink(actual_path($newReportFileName)); // FILE HAS BEEN
FORCE-DOWNLOADED AND IS NO LONGER NEEDED ON SERVER
}
}

}
[/PHP]

Thanx
Phil

Apr 20 '06 #1
0 2636

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

Similar topics

2
by: Matthew Sims | last post by:
Is it possible to force a download without using the readfile function? My website setup consists of my server that serves the web pages plus a high-speed file server elsewhere on the internet...
2
by: Jonathan Driller | last post by:
I am attempting to block repeat downloads from a site. I need to have a landing page pass a referer to a secured page. I have tried a meta refresh redirect and several Javascript redirect...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
0
by: karups | last post by:
hi, Can some one help me out? How to Force file download box when clicking on a link for a .pdf file. Normally it opens the pdf in IE itself, instead it should ask for (open , save and...
3
by: Bouffa | last post by:
Hello everyone, I suppose you all know force-download scripts. The problem is that these scripts don't allow files to be splitted when downloading them via a download manager. I've found a...
2
by: Jan Paul van de Berg | last post by:
I have a piece of software that people can download and a third party promoting that software. In order for them to be able to count the number of downloads, I have to put a tracking code on my...
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
10
by: Mikhail Kovalev | last post by:
Suppose I have something like this $resource = curl_init(); curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($resource,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.