www.webdeveloper.com
Results 1 to 5 of 5

Thread: Refresh page AFTER downloading file

  1. #1
    Join Date
    Feb 2003
    Posts
    102

    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);
    		//////////////////////////////////////
    	}
    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

  2. #2
    Join Date
    Feb 2010
    Posts
    184
    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.

  3. #3
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    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_handlefilesize($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 09:42 AM. Reason: fixed a little code

  4. #4
    Join Date
    Feb 2003
    Posts
    102
    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

  5. #5
    Join Date
    Feb 2009
    Posts
    102
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles