Jump to content

PHP Download Script ...


bsamson

Recommended Posts

Hello,
  Could someone please direct me in the direction of a php download script. Here's my situation.

I have many document types on my site including, PDF, DOC, XLS, and many more. With that said if a user clicks a link the document opens in IE. I am trying to figure out a way when a user clicks a link to one of these docs that it prompts them w/ a download dialog box. Again, any assistence would be GREATLY appreciated!

Best Regards,
Brian Samson
Link to comment
Share on other sites

Hello. After testing the script ... I think it is corrupting my pdf files ...

Here's my code:

[code]<?php

// would reference script with: http://internal.mydomain.com/scripts/force.php?f=doc.pdf

$pth = "http://internal.mydomain.com/docs/";
$f = $_REQUEST['f'];
$file = $pth . $f;

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($file));

header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));

header("Content-Description: File Transfer");
@readfile($file);

?>[/code]

  When I attempt to open once downloaded I get this error in adobe:

[i]  Adobe Reader could not open 'doc.pdf' because either it is not a supported file type or because the file has been damaged (for example, it was sent as an email attachement and wasn't correctly decoded.)[/i]

  But When i download directly it works fine ... any suggestions? Thanks!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.