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);
//////////////////////////////////////
}
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?
after the file has download, it refreshes the current page to reflect the new data that was just uploaded
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:
PHP Code:
$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)
Last edited by SrWebDeveloper; 02-05-2010 at 08:42 AM.
Reason: fixed a little code
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.
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.
-Steve
"Build a man a fire and he'll be warm for a day. Set a man on fire and he'll be warm for the rest of his life."
Bookmarks