I am creating script to download some files using download dialog box.First time i tried to use ajax for this, but i failed.
So i went through this way,
By Using this function i am going to submit the Data to process to PHP.
JS Function:
Expand|Select|Wrap|Line Numbers
- function file_down(fid)
- {
- window.location = "download.php?fid="+fid;
- }
Calling Function
[PHP]<a href="javascript:file_down('.$row['p_id'].')" ><img src="images/down.jpg" /></a>[/PHP]
download.php
[PHP] <?php
$fid = $_REQUEST['fid'];
require 'dbcon.php';
$sql="SELECT p_man FROM products where p_id = '$fid'";
$result=mysql_query($sql) or die("File Not Found : " . mysql_error());
$row = mysql_fetch_assoc($result);
$file = $row['p_man'];
$FILE_ROOT = "user_manuals/";
$path = $FILE_ROOT.$file;
if($file)
{
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($path));
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile($path);
}
else
{
/*If the file Name is Not Available in the Table,
I need to OPen another POP UP window to display the File Not Found Message.
Or Any Other way to Display the Eror.
*/
}
?>[/PHP]
When I am sending ID from JS function to PHP side it will OPEN the save as Dialog box. But if the File Name is Missing in the table ERRORS will Display under download.php. What i need actually prevent this probleme. That means i want to I am not going to redirect th user back to the Download.php page if errors found.
In that case from the first page itself i want to display a ERROR window.
JS or HTMP Pop up.