Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with csv export

Status
Not open for further replies.

krisc13

Programmer
Jul 17, 2006
42
US
I have a page in my program with several links. One link creates a csv file based on the information on the page. I get a nice excel spreadsheet for opening or saving. However, once the user has chosen to export the csv and does so, the other links on the page ALL open up the csv. You're trapped. There is one link to another section altogether that works, but everything else in this section causes the csv to try and download. All these links work fine until you export the csv. Does anyone have any suggestions on how to un-trap my user? Any ideas would be helpful. Thanks!
 
I know I've been thinking that I'm sorry. I'm just not sure what code to show. I'll post again if I can determine what information to provide here. I apologize for the wasted post.
 
Okay here's the code that creates the csv...

Code:
$output_file = 'MyExportedData.csv';
if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Content-Transfer-Encoding: none');
header('Content-Type: application/octetstream; name="' . $output_file . '"'); //This should work for IE & Opera
header('Content-Type: application/octet-stream; name="' . $output_file . '"'); //This should work for the rest
header('Content-Disposition: attachment; filename="' . $output_file . '"');

echo $my_data;
exit();

Obviously I populate my_data with my values prior to these lines. The dialog pops up for open or save and it works great. When I click any other link on the main page now however this csv just downloads again. I'm trapped on the page. I don't really know what to show you on the main page as these are just links that don't work now. It's nothing functional. Is there something I can put after exit() in my csv code that will redirect the header? I'm sorry if this is unclear. I'm at a bit of a loss. Thanks again.
 
They just point to other pages. For example

Code:
<a href="index.php?panel=report&rpt=2">
<span>
<? echo $report['name']; ?>
</span>
</a>

This link points to a page for creating mailing labels. Sorry for the lack of clarity.
 
So ever though all these links appear to point different places, they all really point back to your csv-creating script? That's weird.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Yeah that's what I thought too! You're trapped on the page with the download link. And all that works is the download of the csv. It's very odd. And I'm very stuck. lol.
 
No, it's not weird. It's unusual in the extreme.

Are you using any multifunction scripts which require input parameters to do separate things?
Do you have any DHTML going on? Holding down your shift key when clicking on the CSV link should get any interaction to happen in a new window. Whan happens to the links on the old window?




Want the best answers? Ask the best questions! TANSTAAFL!
 
Okay I tried holding down the shift key and when I go back to the page the links still try and open the csv. I am not using any DHTML. I have an index page that determines certain things that open. My csv is here...see "case csv":

Code:
function get_page_source($page_name) {

$page_name = strtolower($page_name);
if (!isset($_SESSION['main_page'])) {
	$page_name = 'mpl';
}
switch ($page_name) {
case 'amn':
$_SESSION['main_page'] 		= '/admin.php';
$_SESSION['main_page_id'] 	= 18;
break;
				
case 'usr':
$_SESSION['main_page'] 		= '/user.php';
$_SESSION['main_page_id'] 	= 17;
break;

case 'logout':
$_SESSION['main_page']		= '/logout.php';
$_SESSION['main_page_id']	= 1;				break;

case 'mpl':
$_SESSION['main_page']		= '/main.php';
$_SESSION['main_page_id']	= 1;
break;

case 'csv':
$_SESSION['main_page'] = '/interface/user/reports/createcsv.php';
$_SESSION['main_page_id'] = 1;
break;
}

if (isset($_GET['page']) && !(isset($_GET['view']))&& !(eregi('http', $_GET['page']))){
$_SESSION['main_page'] = $_GET['page'];
$_SESSION['main_page_id'] = 1;
}
		
return INCLUDE_DIR . $_SESSION['main_page'];
 
What does $_SESSION['main_page'] do?

It looks to me like your links to not after all point to different places but rather point to a single place, a switchboard, which then redirects the browser or runs an external program or proxies the connection or something.

Once you've output the CSV, do you change that session variable to point to something else?



Want the best answers? Ask the best questions! TANSTAAFL!
 
I took a closer look at that function. The link I referred to earlier was
Code:
<a href="index.php?panel=report&rpt=<? echo $num; ?>">

I changed it to
Code:
<a href="index.php?view=usr&panel=report&rpt=<? echo $num; ?>">

And now it works just fine. Doesn't trap you in the page. Apparently I have to use one of the cases from my switchboard like page to force it out of the csv page. I can't thank you enough for helping me. This has been driving me crazy. I appreciate your input very much! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top