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
https://forums.phpfreaks.com/topic/197896-problems-with-downloadphp-script/
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.