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

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);
}

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

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.