rahuul Posted March 23, 2011 Share Posted March 23, 2011 hi... I have a site that allows user to download some files. at present if i type http://www.abc.com/files/xyz.zip it allows all the users to access and download files. I want only the login users can access these files....... pls help how to do this. thanks in advance Quote Link to comment Share on other sites More sharing options...
aabid Posted March 23, 2011 Share Posted March 23, 2011 <? $dir="/path/to/file/"; if (isset($_REQUEST["file"]) && _SESSION["loggedin"] = TRUE) { $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)."""); while(!feof($file)) { $buffer = fread($file, 2048); echo $buffer; } else { echo "No file selected"; } ?> May be this can work for you although i haven't tested it, so am not sure. I bet there might be some other ways better than that to do the stuff Quote Link to comment Share on other sites More sharing options...
rahuul Posted March 23, 2011 Author Share Posted March 23, 2011 hi... thanks for your reply..... but if a user directly access http://www.abc.com/files/xyz.zip without opening any page of my site who will i use this type of php script. Quote Link to comment Share on other sites More sharing options...
aabid Posted March 23, 2011 Share Posted March 23, 2011 Using session variable like _SESSION[loggedin] ensures that the user is logged in and in turn is on your site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.