Jump to content

problems with download.php script


flipper828

Recommended Posts

I have a site that requires login and password to access.  It works fine.  However, the downloadable documents (.doc and .pdf) meant only for logged in users, are available for anyone regardless of whether they are logged in or not. 

 

In my research, I found a way to mask the url for the download files by using a download.php script.  I implemented the script and am having problems. 

 

When I click the link for a .pdf, all SEEMS to be working as it should. But when I try to open the .pdf, I get this message:

Acrobat could not open "filename.pdf" because it is either not a supported file type or because file has been damaged........
 

 

When I click the link for the .doc, again all seems to go well until I open the document.  The Word document opens up with this message:

 

<br />

<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for /home/administrator/docs/trc/filename.doc in <b>C:\wamp\www\download.php</b> on line <b>12</b><br />

<br />

<b>Warning</b>:  readfile(/home/administrator/docs/trc/filename.doc) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: No such file or directory in <b>C:\wamp\www\download.php</b> on line <b>14</b><br />

 

This is the code from my download.php file

 

<?php
session_start();
if (! $_SESSION['ug_user']) {

    header("location:login.php");
}
$dir="/home/administrator/docs/trc/";
if (isset($_REQUEST["file"])) {
    $file=$dir.$_REQUEST["file"];
    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment; filename=\"".basename($file)."\"");
    readfile("$file");
} else {
    echo "No file selected";
}

?> 

 

When I set up the link, it looks something like this:

 

<a href=\"http://example.com/download.php?file=filename.doc\" target=\"_blank\"><img src=\"images/word_icon.jpg\" alt=\"Word download icon\" width=\"25px\" height=\"25px\" border=\"0\"></a>   <a href=\"http://example.com/download.php?file=filename.pdf\" target=\"_blank\"> <img src=\"images/pdf_icons_03.jpg\" alt=\"PDF download icon\" width=\"20px\" height=\"30px\" border=\"0\"></a>

 

Both documents are in working condition.  Please help?  If you need any other information, please don't hesitate to ask.

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.