/    Sign up×
Community /Pin to ProfileBookmark

Refresh page AFTER downloading file

Hi all,

At present, I have a form that submits a URL to a page (via POST) amongst other data. The page then adds the data it needs to into a MySQL database, after which it then proceeds to download the file specified in the posted URL. Here’s the code so far…

[CODE] //set download date and time to time after download has completed… I think… otherwise it will just be the time the form was posted.
$downloaddate = date(‘Y-m-d’);
$downloadtime = date(‘H:i:s’);
//Insert download date/time into tblFilesUploaded
mysql_query(“UPDATE tblFilesUploaded SET DownloadedFileDate=’ $downloaddate’, DownloadedFileTime=’ $downloadtime’ WHERE RecordNum=’ $_POST[RecordToUpdate]’ “)
or die(mysql_error());

//set filename and download file
$file = $DownloadLocation.$_POST[‘FileToDownload’];
if (file_exists($file)) {
header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/zip’);
header(‘Content-Disposition: attachment; filename=’.basename($file));
header(‘Content-Transfer-Encoding: binary’);
header(‘Expires: 0’);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
header(‘Pragma: public’);
header(‘Content-Length: ‘ . filesize($file));
ob_clean();
flush();
readfile($file);
//////////////////////////////////////
//$tabselected = 2;
//header(‘Location: http://www.cityscope.com.au/inhouse/cityscope-DUM.php?tabselection=’.$tabselected);
//////////////////////////////////////
} [/CODE]

What I would like is after the file has download, it refreshes the current page to reflect the new data that was just uploaded.

I have tried several ways of doing this with no luck, one of which you can see commented out and surrounded by ////////////////

Anyone know if this is possible or not… and if possible, how?

Many thanks,

Chris

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@letmehaveagoFeb 05.2010 — i don't think it is possible with php.

using javascript you could open the download in a new page and refresh the old page.
Copy linkTweet thisAlerts:
@SrWebDeveloperFeb 05.2010 — after the file has download, it refreshes the current page to reflect the new data that was just uploaded
[/QUOTE]

Unless I misunderstand the request, after the form is submitted, database updated and URL is known, use "fopen" to retreive the data from the URL and do with it as you please:

[code=php]$ini_handle = fopen($file, "r");
$file_contents = fread($ini_handle, filesize($file));
fclose($ini_handle);
echo $file_contents; // whatever you need to do, do it here (example only)

[/code]
Copy linkTweet thisAlerts:
@Chris_JacksauthorFeb 10.2010 — Hi SWD,

Many thanks for your previous post. Apologies for the delayed reply. I don't think that will work for what I need it to.

Let me explain in a little more detail...

In short, I have a form that when submitted, downloads the filename specified in a hidden field in the form. At the same time it downloads the file, it also successfully writes the date and time to a column in the database titled "DateTimeLastDownloaded".

The problem is, that after downloading the file, the page needs to be "refreshed" before it will show the new "last downloaded date" in the list.

I have created a basic meta refresh button on the page that the user can click to refresh the page (which then shows the new date) but this is a bit of a cop-out. I'd rather the page automatically (and instantly) show the new date last downloaded.

Any ideas?... class... anyone?

Thanks again!


Chris
Copy linkTweet thisAlerts:
@StevishFeb 10.2010 — I really think you need javascript to do this, unless you want the page to be loading and little to no information displayed (at which point the user might think it's stuck and refresh the page). Then once the download is complete, it can display all the info. You could do that by putting a while loop toward the top of the page (before the "date last downloaded" info is displayed) that will loop until the download is done.

Otherwise, you could set up a javascript/ajax loop that will keep checking every second to find out when the download is done, then update the info.

Basically, once the user sees the page (once it's done loading), php is already done with the file, and can't interact with the user anymore. That is why I think you need some client-side help here.
×

Success!

Help @Chris_Jacks spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...