473,385 Members | 1,856 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,385 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 2638

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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.