wilhud Posted April 16, 2010 Share Posted April 16, 2010 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 https://forums.phpfreaks.com/topic/198702-readfile-on-password-protected-directory/ Share on other sites More sharing options...
l0ve2hat3 Posted April 16, 2010 Share Posted April 16, 2010 Please post your code Link to comment https://forums.phpfreaks.com/topic/198702-readfile-on-password-protected-directory/#findComment-1042788 Share on other sites More sharing options...
wilhud Posted April 16, 2010 Author Share Posted April 16, 2010 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 https://forums.phpfreaks.com/topic/198702-readfile-on-password-protected-directory/#findComment-1042794 Share on other sites More sharing options...
l0ve2hat3 Posted April 16, 2010 Share Posted April 16, 2010 it may be a problem with caching... try adding these headers if it happens again header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past Link to comment https://forums.phpfreaks.com/topic/198702-readfile-on-password-protected-directory/#findComment-1042795 Share on other sites More sharing options...
wilhud Posted April 16, 2010 Author Share Posted April 16, 2010 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 https://forums.phpfreaks.com/topic/198702-readfile-on-password-protected-directory/#findComment-1042804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.