Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 23rd, 2004, 11:16 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Download and Redirection

I need download a file and then redirect to other page.

Currently, i try to do this with:

    function open_download_dialog_box($file, $path) {

        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename = ' . $file);
        readfile($path);
    }


    open_download_dialog_box('test.rar', 'files/test.rar');
    header('Location: http://www.google.com.ar');

If anybody knows how i can do this, i aprecciate your help.

.:: wolverine4277 ::.


 
Old December 23rd, 2004, 03:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I suggest you read the comments on the page
http://www.php.net/readfile

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 23rd, 2004, 04:01 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib, i already read that comments but don´t help me.
Which comments are you talking about????

 
Old December 23rd, 2004, 04:14 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Quote:
quote:Snib, i already read that comments but don´t help me.
Which comments are you talking about????
Are you saying you did read the comments or you didn't find them?

This should do it:

Code:
<?php
$file = '/var/www/html/file-to-download.xyz';
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
?>
-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 23rd, 2004, 04:52 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My script also works, but i can't redirect to another page after that de save as dialog box appears.

 
Old December 23rd, 2004, 05:32 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Ah, a minor misunderstanding on my part. I apologize.

Perhaps you could echo some redirecting JavaScript that redirects once the entire page has loaded, including the file download, I assume.

echo "<script type='text/javascript'>location.replace('nextpage.php');</script>";

-Snib - http://www.snibworks.com
Where will you be in 100 years?





Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Redirection santhosh.irtt Apache Tomcat 1 July 1st, 2006 08:07 PM
Redirection andyw ASP.NET 2.0 Basics 2 May 29th, 2006 05:23 PM
Redirection in webservice suparba .NET Web Services 3 October 27th, 2004 01:15 PM
automatic 'redirection' stu9820 Flash (all versions) 4 September 20th, 2004 07:29 AM
Redirection a5xo3z1 Beginning PHP 4 June 19th, 2003 02:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.