[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Use of Global Variable When Exporting / Downloading Content

Within an 'if' statement, I'm defining a variable that I'd like to be global. When I then export to text file for download, I'd like to use that variable to define the filename.

Not sure how to get this to work. Any assistance would be appreciated.

Here is some excerpt from what I currently have:

<?php
//
if( isset($_REQUEST['action']) && ( strval($_REQUEST['action']) == 'export') )      {
      header("Content-Type: application/txt");
      header("Content-Disposition: attachment; filename=$nameOfFile.xls");
}

if( $action != "export") {
      global $nameOfFile = "test.txt");
      ?><a href='?action=export'>Export</a><?php
}

if( $action == "export") {
      echo "This is just a test";
}
?>
0
deharvy
Asked:
deharvy
1 Solution
 
hieloCommented:
I think you want something similar to the following:
<?php
session_start();
//
if( isset($_REQUEST['action']) && ( strval($_REQUEST['action']) == 'export') )      {
      header("Content-Type: application/txt");
      header("Content-Disposition: attachment; filename={$_SESSION['nameOfFile']}.xls");
}

if( $action != "export") {
      $_SESSION['nameOfFile'] = "test.txt");
      ?><a href='?action=export'>Export</a><?php
}

if( $action == "export") {
      echo "This is just a test";
}
?>

Open in new window

0
 
deharvyAuthor Commented:
Brilliant! This is exactly what I wanted and needed. It has been a while since you helped me with a problem and it's good to have you back. :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now