3 Replies - 1270 Views - Last Post: 03 February 2012 - 01:20 AM Rate Topic: -----

#1 newuser22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

force download for file types other than pdf

Posted 02 February 2012 - 12:20 PM

hi, my code works fine for the pdf only,users can view pdf files on their browser or save the file. However, I would like to force download for other file types(doc,ppt).

p.s: i tried doing so by changing inline to attachment,it worked but it forces download for pdf as well.

header('Content-Disposition: inline; filename="' . $filename . '"');



Complete code:
$file = 'dir/file.pdf';
$filename = 'file.pdf';


header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);


Is This A Good Question/Topic? 0
  • +

Replies To: force download for file types other than pdf

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4214
  • View blog
  • Posts: 13,317
  • Joined: 08-June 10

Re: force download for file types other than pdf

Posted 02 February 2012 - 12:43 PM

you would need to send the attachment property for all files that are not PDF and inline for PDFs.

alternatively, you could try to change the server settings via .htaccess
Was This Post Helpful? 0
  • +
  • -

#3 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: force download for file types other than pdf

Posted 02 February 2012 - 12:48 PM

Hey,

Try changing the content type to application/octet-stream. Another thing to note is you shouldn't be using the @ operator to silence error messages. Instead, use a error handler.
Was This Post Helpful? 0
  • +
  • -

#4 newuser22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: force download for file types other than pdf

Posted 03 February 2012 - 01:20 AM

Thank you #3 codeprada and #2 Dormilich. it works fine now :clap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1