Page Stuck After Force Download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Page Stuck After Force Download

Post by thomas777neo »

Hi All

I have generated an excel spreadsheet, which I force download using this code:

Code: Select all

<?php
header('Content-Description: File Transfer'); 
header('Content-Type: application/force-download'); 
header('Content-Length: ' . filesize($filename)); 
header('Content-Disposition: attachment; filename=' . basename($filename)); 
@readfile($filename); 
?>
Yet, after clicking on the link that sends the $filename to the stipulated code.

I cannot go to any other page on the menu I have that is in the leftFrame. The current active page where I downloaded the file from is stuck.

Any suggestions?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

what i ended up doing which works for me is

Code: Select all

&lt;a href="download.php?fileToDownload=nameOfFileToDownload.csv&gt;
then in download.php

Code: Select all

<?php
if(isset($_GET['fileToDownload']))
{
header('Content-type: application/csv');
$fileToDownload=$_GET['fileToDownload'];
// It will be called downloaded.pdf
header("Content-Disposition: attachment; filename="$fileToDownload"");
readfile("./outfile/$fileToDownload");
}
else
  echo "unable to find ".$_GET['fileToDownload'];
?>
which opens up the open/save dialague box and the links on my original page still work.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

looks like there might be an error in the readfile function. Remove the @ as it supresses any errors.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Still problematic

Post by thomas777neo »

Your code definitely brings up the save box, I can also save the file.
But if I click on my menu item which is in a separate frame. The main (page loading) frame remains stuck.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

removed @

Post by thomas777neo »

It still works, yet the same problem persists
Post Reply