Need Help Please! How do I get my uploaded pdf to prompt people to download it?

Discussion in 'C#' started by rob33, Feb 9, 2009.

  1. #1
    Probably not explaining this well but my pdf url is:

    http://rescuerelationship.info/MagicOfMakingUp.pdf

    instead of it just being hosted - how - when people click on this link can i get a "save" window pop up asking the surfer to open or save this file?

    How is this done - thanks guys,,..
     
    rob33, Feb 9, 2009 IP
  2. ASPkit

    ASPkit Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The easy way is to put the pdf in a zip file.
    Another option would be to use the following PHP code:

    
    <?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>";
     }
     ?>
    
    PHP:

    Save this little snippet as a PHP file somewhere on your server and you can use it to make a file download in the browser, rather than display directly.
    If you want to serve files other than PDF, remove or edit line 5.

    You can use it like so;

    Add the following link to your HTML file.
    <a href="download.php?file=my_pdf_file.pdf">Download the cool PDF.</a>
     
    ASPkit, Feb 10, 2009 IP
  3. Bruce_Davenport

    Bruce_Davenport Guest

    Best Answers:
    0
    #3
    thnks for the code..
     
    Bruce_Davenport, Feb 10, 2009 IP
  4. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #4
    I don't think it's good to force people to download pdf files to their PCs
     
    vihutuo, Feb 12, 2009 IP