I have designed an application that allows a user to download a pdf. When the user clicks the download link a javascript function runs that opens a new window for this download and will then redirect the first page to another page in the site.
However I am having the problem of the javascript redirect does not successfully open the intended download. If I use a basic link then this works fine however when javascript is introduced errors happen.
Below is my code I would be grateful if anyone has any ideas as to the problem, thanks
Code: Select all
<Script Language="JavaScript">
function load() {
window.open('download.php?act_id=<?php print $act_id;?>');
}
// -->
</Script>the fnction that runs the download:
Code: Select all
function download_file($product_code)
{
$row = activity_query($product_code);
$location = $row['location'];
$path ='../../../../fenman_learning_resource_products_05/'.$location.'';
if (file_exists($path))
{
$size = filesize($path);
$file = basename($path);
header ("Content-Type: application/octet-stream");
header ("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$file");
header("Content-Length: $size");
readfile($path);
//update user's credits
deduct_credits($product_code);
//send confirmation email
confirm_email($product_code);
}
else
{
header("Location: $path");
}
}thanks
alex