I am using a ajax script to send the file IDs and PHP will process it and it should generate the save as dialog box.
Currently without ajax when i process PHP file i can open the download box to save the file.
example:
http://localhost/website/download.php?fid=1005
but when i am sending the fid (using a onclick event of a Image i am sending the ID to JS func ) through Ajax Script this PHP file will execute in server side. so can't retrieve those headers to the page i am sending the request. is there any way to Open this dialog box. issue is now the PHP fle is executing in server side, i have to call it in client side as i feel.
Expand|Select|Wrap|Line Numbers
- var xmlHttp;
- function GetXmlHttpObject()
- {
- var objXMLHttp=null;
- if (window.XMLHttpRequest)
- {
- objXMLHttp=new XMLHttpRequest();
- }
- else if (window.ActiveXObject)
- {
- objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- return objXMLHttp;
- }
- function file_down(fid)
- {
- xmlHttp=GetXmlHttpObject();
- if (xmlHttp==null)
- {
- alert ("Your Browser does not support AJAX, please Update!");
- return;
- }
- var url="download.php?fid="+fid;
- url=url+"&zid="+Math.random();
- //xmlHttp.onreadystatechange=stateChanged_file_down;
- xmlHttp.open("GET",url,true);
- xmlHttp.send(null);
- }
- function stateChanged_file_down()
- {
- if (xmlHttp.readyState==4)
- {
- // Can't guess what to do here....
- }
- }
<?php
$fid = $_REQUEST['fid'];
require 'dbcon.php';
$sql="SELECT p_man FROM products where p_id = '$fid'";
$result=mysql_query($sql) or die("Error Occured while Searching Records : " . mysql_error());
$row = mysql_fetch_assoc($result);
$file = $row['p_man'];
if($file)
{
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($file));
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile($file);
}
?> [/PHP]