I want to write a file-download page for customers to download files from my company servers.
And I don't want to expose the real file link to users, so I have two pages : filelist.php for offering a link to click and posting the file name as parameter to the other page, named download.php , accepting the request and transferring file stream to customers.
The key part of download.php is like this:
$fp = fopen($real_file_path,'r');
$file_size = $temp_res['ef_file_bytes'];
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".$file_size);
Header("Content-Disposition: attachement;filename=".$file_name);
echo fread($fp,$file_size);
fclose($fp);
exit;
Now I use an onclick() function in filelist.php ,when the file link is clicked ,the function following is called:
function downloadfile( ef_name )
{
var url_str='download.php';
url_str = encodeURI(url_str);
$.post(
url_str,{fnm:ef_name },
function(data){
window.open().document.write(data);
}
);
}
But I can only show the file's content in page rather than popping up a dialog-window to save it.
If I use to test , it works well.
The the 'data' in JS code above is exactly the whole content of the file I want to down load. I think the question is in the function I used in $.post(); Is there any function in javascript can open a new page with post parameter ?
I'm on windows , apache ,php,mysql.Thanks!