Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Download Dialog Box  (Read 2975 times)

0 Members and 1 Guest are viewing this topic.

evergreensteve

    Topic Starter


    Starter

    Download Dialog Box
    « on: March 03, 2009, 02:06:54 AM »
    I want to download pdf or doc files to visitors at my website.  When I put them on my server and link to them the document appears.  I would like to have a dialog box appear.  I have not been able to describe it very well in the past so I have loaded a screen capture of the box I want to appear at http://stevestory.com/dialogbox.html.  This has confused me for months- any help would be greatly appreciated.Thanks

    Computer Hope Admin

    • Administrator


    • Prodigy

      Thanked: 248
      • Yes
      • Yes
      • Yes
      • Computer Hope
    • Certifications: List
    • Computer: Specs
    • Experience: Guru
    • OS: Windows 10
    Re: Download Dialog Box
    « Reply #1 on: March 03, 2009, 09:12:21 AM »
    If the file extension is a recognizable format (e.g. .PDF, .DOC, .XLS) by default all browsers will use the associated program to open the file. There are a few things that can be done.

    1.

    You could suggest to the visitors to right-click the file and choose save as if they don't want to open the PDF.

    2.

    If you're familiar with PHP you could create a PHP file called download.php and add the below code to the file.

    Code: [Select]
    <?php   if (isset($_GET['file'])) {
        
    $file $_GET['file'];
           if (
    file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file))  {
              
    header('Content-type: application/pdf');
            
    header("Content-Disposition: attachment; filename=\"$file\"");
                  
    readfile($file);
           }
        } else {
        
    header("HTTP/1.0 404 Not Found");
        echo 
    "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
     }
     
    ?>


    Once this is added you can change your links to something such as:

    http://www.computerhope.com/download.php?file=example.pdf

    If the example.pdf file exists it would then prompt the user to download it. Otherwise generate a 404 error.

    Hope that helps.

    Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
    -Albert Einstein

    evergreensteve

      Topic Starter


      Starter

      Re: Download Dialog Box
      « Reply #2 on: March 06, 2009, 04:48:33 PM »
      thanks.  i will give it a try.

      Computer Hope Admin

      • Administrator


      • Prodigy

        Thanked: 248
        • Yes
        • Yes
        • Yes
        • Computer Hope
      • Certifications: List
      • Computer: Specs
      • Experience: Guru
      • OS: Windows 10
      Re: Download Dialog Box
      « Reply #3 on: March 07, 2009, 12:50:33 PM »
      Because I've got this question a few times and know it's a popular question I've also wrote the below document for future reference.

      http://www.computerhope.com/issues/ch001113.htm

      Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
      -Albert Einstein