i have a website which i sell my books on, now i want to redirect my users to the home page (index.html) when they click the download link and the file starts to download.

Will really appreciate the help and support thanks.

this is the php code i wrote

<?php
$fakeFileName= "e-book_mobi.mobi";
$realFileName = "e-book_mobi.mobi";

$file = "book/". $realFileName;
$fp = fopen($file, 'rb');

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fakeFileName");
header("Content-Length: " . filesize($file));
fpassthru($fp);
exit;
?>

this is the download link

<li><a href="mobi_download.php?id=<?php echo $_GET['id']; ?>" target="_blank"/><b>.mobi</b></a></li>
Member Avatar for diafol

I'm not sure that this is possible. But why not redirect first and then force the download?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.