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
https://forums.phpfreaks.com/topic/28941-php-download-script/
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
https://forums.phpfreaks.com/topic/28941-php-download-script/#findComment-132555
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.