Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Member #
    36952

    .htaccess file not work - need help

    I was hoping someone could help me out here. I just created a new webpage with hostgator and I placed a .htaccess file in the public_html folder to force download of a pdf. For some reason it's not working. I've used the exact same .htaccess file on a webpage through hostgator a couple of years ago and it worked perfectly back then. Here is the script in the file:

    <Files *.PDF>
    ForceType application/pdf
    Header set Content-Disposition attachment
    </Files>

    I've also tried:

    AddType application/octet-stream .pdf


    What could be wrong? The directory setup of my webpage files? Some sort of conflict between the webpage html and this .htaccess file?

    Any help on this would be much appreciated. I just spent half a day yesterday looking for answers to this with no luck.

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Actually... Don't think its a .htaccess thing as much as a browser security thing...

    if you can find a PC with IE6, that will probably still work... But with the "PDF malware" issues a couple years ago... Browsers normally can't be forced to open a "HTML" or "PHP" file as a PDF...

    If you use the application/ type as a variable so when someone clicks a link to the same page... But its delivered as a "PDF"... It should work... But an htaccess mod-rewrite ... So the browser is "forced" to open an application type different than the "request"... I think most browers blocked that several versions back...

    ' then again... It might be just a bad mod-rewrite engine on HG again

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    As a workaround, although I'm not sure how you'd do this in PHP, you could have them click on a PHP link that sends the file as an octet stream to the user's browser. I've done this in ASP/ASP.net with Excel spreadsheets, but never with a PDF and never in PHP.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Yup, I have a client that pulls hundreds of reports from a massive DB, and on each of those pages is a link or button to export to excel. But those are windows servers. So the application/octet-stream works without anything else needed ( other than the user having some sort of excel reader or program on it )... For the save API.

    for PDF to work, you need a class or API to finish the conversion ( win servers )... Linux servers have that class/module ( or many do ), to force the browser to PDF output. But there's an internal "reference" ( I believe ), that requires the http_referer to be the same page if not at least the same domain. Or the link being requested must be a .pdf . Sure you can link directly to a PDF ... But the htaccess mod-rewrite from a non-defined link class to a PDF output ... Could be a dangerous thing as there are still millions of unpatched, vunerable installs of adobe reader.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:46 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com