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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

probably a simple workaround...please help

Status
Not open for further replies.

baza

Programmer
May 15, 2001
20
ES
Hi,

I am building a site for a client, that allows its users to select files and add to mysql db, then when they click download, it zips up all the files and downloads then for the user.

it all works great, problem I have is with the download basket.

I add the file to the db when the user clicks add to basket and then call the basket page which updates the basket.

Problem I have is when the user clicks download, the zip.php page is called from the hyperlink and that does the zip magic, but the basket does not update, leaving the original items count in the basket.

I created an ajax basket which checked every couple of seconds and that worked wonderful, that is, until I tested on the dreaded IE7. AGGGHHHHHHHHHH!!!!

anyway, I am no ajax whizz and think its would be simpler if I stayed away from spending days trying to hack the ajax code for IE7

So my question is, is there a way for the zip page to send a refresh to the index page to refresh, hence refreshing the basket.

heres the snippets of code that I use


on the basket page i have

<?
$user_id=$_SESSION['user_id'];

$sql = "SELECT * FROM zips WHERE user_id = '$user_id'";
$rs = mysql_query($sql) or die(mysql_error());
$numrows=mysql_num_rows($rs);
?>


<div class="basket_top">
Basket :
<?
echo $numrows;
?>
&nbsp;Items;
<?
if($numrows>0)
{
echo "<br><a href='zip.php'>Download Files</a>";
}
?>
</div>


and on the zip.php page I have this

<?
session_start();
require("application/connect.php");

function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();
//then send the headers to foce download the zip file



header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
unlink($archive_file_name);
unlink($file_path);
exit;

}


$file_names=array();
$user_id=$_SESSION['user_id'];
$i=0;
$sql="SELECT * FROM zips WHERE user_id='$user_id'";
$rs=mysql_query($sql);
while ($row=mysql_fetch_array($rs))
{
$file_names[$i]=$row['file'];
$i++;
}
mysql_query("DELETE FROM zips WHERE user_id='$user_id'");
$archive_file_name='zippy_files/windrush_files.zip';
$file_path=dirname(__FILE__).'/zippy_files/'.$user_id.'/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);

?>



Now I know that I want the page refresh to be just after the two unlink calls, but for the life of me I cannot fathom it out.

I have tried to refresh at the same time as the zip.php page call, but the db has not been updated at that point so the basket remains full.


any help would be wonderfully accepted.

thanks in advance

Barry


 
This is a job for... Javascript!.

PHP cannot interact with the browser like that.

Since you aren't opening a new page to load zip.php perhaps just redirecting back to basket.php would work.

If you are opening a new page to run zip.php, then maybe using the opener reference to your other window and issuing the reload command to it would also work.

In both cases it would be done by Javascript.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top