Click here to Skip to main content
15,867,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello!

I'm developing a webpage that will commence a download file process when visited.

Then will automatically redirect to another page.

I've tried using the following code below, but it doesn't work. It only redirects to another page without downloading the file.

Please does anyone know a better way to accomplish both?

Kindly respond, thnaks.

XML
<?php
/* Redirect browser */
header("Location: http://www.google.com/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="rhapsody of relaities, daily, daily devotional, Christ Embassy, mobile downloads, ebook readers, ios, android, devotional, christian, gospel, pastor chris,pastor, chris, free download, Channel, TV, pastor chris teaching, atmosphere for miracles, special videos, faith speaks"/>
<title>Hello!</title>
<link rel="stylesheet" type="text/css" href="css/style.css">

</head>

<body>
<?php
$file = 'July-2013.pdf';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>
Posted
Updated 18-Jul-13 22:37pm
v2
Comments
zenspace 19-Jul-13 4:54am    
Why not use Javascript to redirect?
namo77 19-Jul-13 5:16am    
The Javascript doesn't work either.
Mohibur Rashid 21-Jul-13 21:59pm    
what did you try with your javascript?

1 solution

check this out
this is your answer [^]
 
Share this answer
 
Comments
namo77 19-Jul-13 7:28am    
Thanks, but its still not working.
namo77 19-Jul-13 10:04am    
Please does anyone have a solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900