Jump to content

readfile on password protected directory


wilhud

Recommended Posts

Hello,

 

I've setup a script that pulls files from a folder using readfile and creates the proper headers (content-type, content-disposition, etc.) in order to send the file to the browser. It works great but when I drop the script and the files in a password protected directory, all the files come out as plain text. For Example, outside the password protected directory, a WMV file loads up inside my Windows Media player. However, when I run the exact same script inside of a password protected directory, the file just displays as plain text and the media player never loads. Both the file and the script are inside the same password protected area and I have logged in prior to running the script. I'm more of a graphic designer than a programmer, so I'm sure it's something I'm just not doing right. I've searched for other people having similar issues on numerous sites and haven't been able to find anyone talking about this particular issue. Any feedback would be greatly appreciated.

 

Thanks,

Wil

Link to comment
Share on other sites

Oddly enough, I logged out and logged back into the server and it suddenly started working. I will have to do some more testing to see if it was just an anomoly.

 

Here's the code:

 

$path = "/".$type."/".$cat."/".$file;

$fullpath = realpath("archive").$path;

if (!is_file($fullpath)) {
  exit('File not found');
} else {
  $size = filesize($fullpath);
  header("Content-Type: ".$filetype);
  header("Content-Description: File Transfer");
  header("Content-Disposition: inline; filename=\"".$file."\"");
  header("Content-Length:".$size);
  readfile($fullpath);
}

Link to comment
Share on other sites

So far so good. I went ahead and added the chache headers you recommended and have not had any problems since. I'm going to load a bunch of files in and link them throughout the site so I can test the script more in depth. Hopefully it holds up.

 

Thanks L2H!

 

Wil

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.