Hello,
I want to open a file from database folder based on the link.If the user wants to view the particular file means and when they clicks on that particulat link it should ask ,Do u want to open or save? Like this....
But i created direct download by using link.Its works fine.
So if anyone knows let me know...
This is my download file.
[/code]
<?php
if (isset($GET['resume']) && basename($GET['resume']) == $_GET['resume']) {
$filename = $_GET['resume'];
} else if(isset($GET['sdoc']) && basename($GET['sdoc']) == $GET['sdoc']) {
$filename = $GET['sdoc']; }
else {
$filename = NULL; }
// define error message
$err = '<p style="color:#990000">Sorry, the file you are requesting is unavailable.</p>';
if (!$filename) {
// if variable $filename is NULL or false display the message
echo $err;
} else {
// define the path to your download folder plus assign the file name
$path = 'documents/'.$filename;
// check that file exists and is readable
if (file_exists($path) && is_readable($path)) {
// get the file size and send the http headers
$size = filesize($path);
header('Content-Type: application/octet-stream');
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
$file = @ fopen($filename, 'r');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file) or die(mysql_error());
exit;
} else {
echo $err;
}
} else {
echo $err;
}
}
?>