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;

    }

}

?>

    You can't force the open/save dialogue on browsers, you can only force a download. If you leave out the Content-Disposition header the browser will perform its default action. You've not said what format this file is in, so it might behave differently for different people:

    • PDF - if the browser has a PDF viewer it might open in the browser. Chrome has one built in, Adobe provide a plugin for browsers on Mac/Windows, but a user may not have that OS or the Adobe Reader (I personally don't as I prefer a reader with less security holes and less of a tendency to bug me about updates every day)

    • MS Office document - There is a plugin for some Windows browsers that allows these to be opening in the browser, but it's not very popular

    • OpenOffice/LibreOffice document - plugins do exist for major browsers on Mac/Linux/Windows, but they aren't widespread

    • RTF - I don't know first-hand of any browser which handles these files, perhaps one of the Office plugins would

    Personally I'd let the browser do its thing. Bear in mind that people spend time setting up their web browsers the way they like, so to try and make it do something other than what they've set as the default is not always the best idea.

      Ashley Sheridan;11021609 wrote:

      You can't force the open/save dialogue on browsers, you can only force a download. If you leave out the Content-Disposition header the browser will perform its default action. You've not said what format this file is in, so it might behave differently for different people:

      • PDF - if the browser has a PDF viewer it might open in the browser. Chrome has one built in, Adobe provide a plugin for browsers on Mac/Windows, but a user may not have that OS or the Adobe Reader (I personally don't as I prefer a reader with less security holes and less of a tendency to bug me about updates every day)

      • MS Office document - There is a plugin for some Windows browsers that allows these to be opening in the browser, but it's not very popular

      • OpenOffice/LibreOffice document - plugins do exist for major browsers on Mac/Linux/Windows, but they aren't widespread

      • RTF - I don't know first-hand of any browser which handles these files, perhaps one of the Office plugins would

      Personally I'd let the browser do its thing. Bear in mind that people spend time setting up their web browsers the way they like, so to try and make it do something other than what they've set as the default is not always the best idea.

      Thanks for ur reply...

      My file contains document format.When i click on the link first it should open a dialog box in that open or save as button as like that....

        What is document format? .doc, .rtf, .pdf, .odt are all document formats.

        Like I said, you can't force an open/save dialogue box.

          Ashley Sheridan;11021615 wrote:

          What is document format? .doc, .rtf, .pdf, .odt are all document formats.

          Like I said, you can't force an open/save dialogue box.

          .doc files..

          Is there any other way to do like that type?(Open or save as dialog box..)

          If u know means,tell me how to do it...

          thanks in advance,
          simbu.

            Ashley Sheridan;11021609 wrote:

            You can't force the open/save dialogue on browsers, you can only force a download.

            Ashley Sheridan;11021615 wrote:

            Like I said, you can't force an open/save dialogue box.

            I'm not sure how clearer I can be...

              Ashley Sheridan;11021609 wrote:

              You can't force the open/save dialogue on browsers, you can only force a download.

              Ashley Sheridan;11021615 wrote:

              Like I said, you can't force an open/save dialogue box.

              Ashley Sheridan;11021621 wrote:

              I'm not sure how clearer I can be...

              when you get down to it, the [font=monospace]Content-disposition[/font] header is merely a suggestion as well. So, to be absolutely clear, you can't "force" browser X to download the file at all. 🙂

                Write a Reply...