Fine tune xml download to re direct and specify save location

The page attached creates an xml page and prompts for download.  This page is called from a link on a different page.  It goes like this, 1) you want to download info for this project than click the link 2) the link appends the url with parameters and goes to the xmlgeneration.php page (attached) 3) the xmlgeneration page does some creates some recordsets and kicks them out as xml.

This all happens quickly and you never really see the xml generation page, you just are prompted to save the xml document and then your back to the original page.

2 things I would like to tune up:  One is to be able to specify what directory on the local machine to save the xml file to.  Two is to have the original page refresh after xml download.  Part of the xml generation page is to update some info from the page that originally linked to it, that work fine but I have to hit refresh to see the changes....??? I would like to save and as part of script redirect back to original page or somehow refresh.
p.s. Around line 87 is the xml save code.
If this is too tough maybe I will break into two questions.
Thanks!
<?php $cid = "-1";
if (isset($_GET['cid'])) {
$cid = $_GET['cid'];}?><!-- WHICH CLIENT -->
<?php $pid = "-1";
if (isset($_GET['pid'])) {
$pid = $_GET['pid'];}?><!--WHICH PROJECT -->
<?php $uid = "-1";
if (isset($_GET['uid'])) {
$uid = $_GET['uid'];}?><!-- WHICH USER -->
<?php $sid = "-1";
if (isset($_GET['sid'])) {
$sid = $_GET['sid'];}?><!-- WHICH USER -->

<!--BELOW SETS THE CONNECTION FOLDER SOURCE FOR THIS PROJECT, BASICALLY FINDS THEIR NAME IN OUR EVOLVE DB AND THEN ADDS TO THE PATH STRING-->
<?php 	//TO SET A CONNECTION DYNAMICALLY TO THE CLIENT PROJECT DB
		require_once('connections/evolveMainAdmin.php'); 
		mysql_select_db($database_evolveMainAdmin, $evolveMainAdmin);
		$query_client = "SELECT clientFolderName, clientName FROM clientinfo WHERE id = $cid";
		$client = mysql_query($query_client, $evolveMainAdmin) or die(mysql_error());
		$row_client = mysql_fetch_assoc($client);
		$rootLocation="../";
		$folder= $row_client ['clientFolderName'];
		$connection="/connections/clientProject".$pid.".php";
		$projectdb=($rootLocation.$folder.$connection);
	 	require_once($projectdb); 
?>

<?php $uidTempDlTable = "user".$uid."temptable"// CREATES VARIABLE TO LINK TO USERS TEMP TABLE?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_GET['sid'])) && ($_GET['sid'] != "")) {
  $deleteSQL = sprintf("DELETE FROM user1temptable WHERE sid=%s",
                       GetSQLValueString($_GET['sid'], "int"));

  mysql_select_db($database_evolveMainAdmin, $evolveMainAdmin);
  $Result1 = mysql_query($deleteSQL, $evolveMainAdmin) or die(mysql_error());
}


mysql_select_db($database_clientProject, $clientProject);
$query_siteInfo = "SELECT * FROM siteinfo WHERE siteinfo.id = $sid";
$siteInfo = mysql_query($query_siteInfo, $clientProject) or die(mysql_error());
$row_siteInfo = mysql_fetch_assoc($siteInfo);
$totalRows_siteInfo = mysql_num_rows($siteInfo);


// ADD THE SITE TO THE ALREADY DOWNLOADED LIST IN THE FIELDHISTORY TABLE FOR THIS PROJECT
mysql_query("INSERT INTO fieldhistory 
(site, uid) VALUES($sid, $uid ) ") 
or die(mysql_error());  


$query_signInfo = "SELECT * FROM signs WHERE signs.siteId = $sid";
$signInfo = mysql_query($query_signInfo, $clientProject) or die(mysql_error());
$row_signInfo = mysql_fetch_assoc($signInfo);
$totalRows_signInfo = mysql_num_rows($signInfo);

//TO CALL THE XML DOCUMENT AND NAME WITH SITE INFO
header('Content-type: text/xml'); 
$fileName = $folder.".project_".$pid.".site_".$row_siteInfo['siteNumber']; //APPENDS THE XML DOC NAME WITH THE SITE ID 
header('Content-Disposition: attachment; filename="'. $fileName .'.xml"');

// XML OUTPUT BELOW, THIS WILL/SHOULD PROB EVOLVE TO ALLOW FOR SEPERATE ATM PAGE OR HOWEVER ELSE CAN BREAK FOR FASTER DB
echo "<site>" ;
do { 
	echo "<customerId>" . $cid . "</customerId>";
	echo "<projectId>" . $pid . "</projectId>";
	echo "<siteId>" . $sid . "</siteId>";
	echo "<userId>" . $uid . "</userId>";
	echo "<siteNumber>" . $row_siteInfo['siteNumber'] . "</siteNumber>";
  	echo "<siteInfo>";
		echo "<siteAddress1>" . $row_siteInfo['siteAddress1'] . "</siteAddress1>";
		echo "<siteAddress2>" . $row_siteInfo['siteAddress2'] . "</siteAddress2>";
		echo "<siteCity>" . $row_siteInfo['siteCity'] . "</siteCity>";
    	echo "<siteState>" . $row_siteInfo['siteState'] . "</siteState>";
		echo "<siteZip>" . $row_siteInfo['siteZip'] . "</siteZip>";
		echo "<siteContactName>" . $row_siteInfo['siteContactName'] . "</siteContactName>";
		echo "<siteContactEmail>" . $row_siteInfo['siteContactEmail'] . "</siteContactEmail>";
		echo "<siteContactPhone>" . $row_siteInfo['siteContactPhone'] . "</siteContactPhone>";
		echo "<siteInfoComments>" . $row_siteInfo['siteInfoComments'] . "</siteInfoComments>";
  	echo "</siteInfo>";

} while ($row_siteInfo = mysql_fetch_assoc($siteInfo));
do {
	echo "<signs>";
		echo "<signType>" . $row_signInfo['signType'] . "</signType>";
		echo "<signId>" . $row_signInfo['signId'] . "</signId>";
		echo "<signOaw>" . $row_signInfo['oaw'] . "</signOaw>";
	echo "</signs>";
} while ($row_signInfo = mysql_fetch_assoc($signInfo));
echo "</site>" ;?>

<?php
mysql_free_result($signInfo);
mysql_free_result($siteInfo);

?>

Open in new window

bowerdesignAsked:
Who is Participating?
 
theremonCommented:
Ok, my bad - should have thought of that before talking to soon.
Now. You certainly cannot have both using simple http headers. All sites I've seen that are following this procedure either open the download in a new window/tab/popup, or have something like a "landing" page that shows the results of any processing then uses a meta tag to redirect to the file.
Maybe by using a little bit of javascript and (probably) a hidden iframe, you could have the most elegant result.
0
 
theremonCommented:
Hi there

if I understood correctly what you need, then first of all, you cannot choose the local folder the user will save into. That's done by the browser which depends on the user setting to select the download location. You have totally no control over that.
Secondly, I think what you want to do about the refresh is simply covered with a header() statement. So, if your originating script is called downloadprompt.php, you can add:

header("Location: downloadprompt.php");

 to the end of the script above and the page will be refreshed.
0
 
bowerdesignAuthor Commented:
I tried it and it does refresh back to the prompting page, but it overrides the prompt for the xml download.  In other words it just goes back without xml production.

I am guessing it because it overrides the initial xml save file header code at line 87?
0
 
bowerdesignAuthor Commented:
Yes It seems that is how it will have to be done.
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.