PHP访问文件目录进行权限验证

福尔摩斯对我笑 2019-02-18 14703 次 1575条
应领导要求,对现有的文件访问进行权限控制,必须登录后才能直接访问文件。 之前做过PHP+Nginx的版本,当时也算勉强实现了。 本来打算利用cookie和apache的配置文件进行权限控制,不过,由于Ecshop登录后并没有cookie,无奈只能放弃。 也考虑过利用Apache判断session,查了很多资料,也没找到解决办法。 今天上了个洗手间,在放飞自我的同时,也放飞了下大脑,想到了解决办法。 其实很简单:查询文件时-》如果存在这个文件-》复制一份到临时目录-》将临时目录中的文件返给前端-》查询时先清空该目录下的文件。

关键PHP代码

//读取该文件
$fp=fopen($file,'r');
$buffer='';
while(!feof($fp))
{
  $buffer.=fgets($fp); //读取二进制流
}
fclose($fp);
//存储新的文件  生成唯一的文件名
$path = "./temp/coa/".uniqid(mt_rand(),1)."_".$coaFileName.".pdf";
$ret  = file_put_contents($path, $buffer);
			
if ($ret) {
  ajax_json('',0,$path, $coaFileName);
}else{
  ajax_json('The read failed, please contact the administrator.');
}

利用.htaccess文件对目录进行访问控制

Order allow,deny
Deny from all
 将该文件放到你要屏蔽的文件目录下,即可。
最后看下,其实也不难,当然我这种方法并不太好。不过这是我目前所能想到的啦。
标签: /

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 1575 条评论 1


  1. lebron 15

    I have to express thanks to you just for bailing me out of this crisis. Because of searching through the internet and finding methods that were not powerful, I figured my entire life was done. Being alive without the presence of approaches to the problems you have solved through the blog post is a critical case, and the ones which might have negatively damaged my career if I had not come across your web site. Your own personal natural talent and kindness in playing with all the pieces was valuable. I don’t know what I would have done if I had not come across such a subject like this. I’m able to now look forward to my future. Thanks so much for the specialized and results-oriented help. I will not think twice to endorse your blog post to anybody who requires care on this problem.

    回复 2019年10月26日
  2. jordan 6

    I intended to create you the little bit of note in order to say thank you over again on the pleasant knowledge you have shared in this article. It is simply surprisingly generous of you giving without restraint what a number of people could have marketed as an ebook to help make some bucks on their own, particularly seeing that you could possibly have done it if you desired. These suggestions likewise acted as the fantastic way to understand that some people have a similar eagerness just as mine to understand whole lot more regarding this issue. I believe there are some more fun instances up front for individuals that look over your website.

    回复 2019年10月26日
  3. adidas yeezy

    I simply wanted to construct a brief comment to be able to say thanks to you for these wonderful tips and hints you are sharing on this site. My prolonged internet investigation has finally been paid with pleasant insight to go over with my neighbours. I would assume that many of us visitors are undeniably blessed to dwell in a remarkable website with so many outstanding people with great methods. I feel somewhat lucky to have encountered the website and look forward to so many more entertaining moments reading here. Thanks a lot once more for all the details.

    回复 2019年10月25日
  4. nike air max 270

    I wish to express my thanks to the writer just for rescuing me from this type of issue. Because of searching through the world-wide-web and obtaining proposals which were not powerful, I thought my life was well over. Living without the presence of approaches to the issues you have solved by way of your entire posting is a critical case, and the ones that would have in a wrong way affected my entire career if I had not noticed your blog post. Your good capability and kindness in controlling all the pieces was vital. I am not sure what I would have done if I hadn’t encountered such a stuff like this. I am able to now look ahead to my future. Thank you very much for this specialized and amazing guide. I will not think twice to suggest your blog post to any person who should receive guide about this topic.

    回复 2019年10月25日
  5. retro jordans

    I actually wanted to jot down a quick note to be able to appreciate you for these unique suggestions you are giving out here. My time consuming internet search has at the end been honored with wonderful know-how to talk about with my relatives. I would tell you that we visitors are very much fortunate to dwell in a decent community with many wonderful individuals with great strategies. I feel somewhat blessed to have discovered the webpages and look forward to some more enjoyable times reading here. Thank you again for all the details.

    回复 2019年10月24日
  6. ferragamo belt

    Thank you for all your valuable labor on this web page. My aunt take interest in engaging in investigations and it’s easy to see why. A number of us hear all about the powerful ways you render both useful and interesting thoughts by means of this web site and therefore invigorate response from other people on that point and my princess is actually starting to learn a whole lot. Take advantage of the remaining portion of the new year. You are always doing a remarkable job.

    回复 2019年10月24日
  7. jordan shoes

    I have to show thanks to this writer just for bailing me out of such a predicament. Because of looking out throughout the the web and seeing opinions which are not pleasant, I figured my entire life was well over. Existing devoid of the strategies to the difficulties you’ve fixed by means of your main guideline is a critical case, as well as the kind that would have in a negative way affected my entire career if I had not come across your blog. Your actual expertise and kindness in maneuvering the whole lot was important. I don’t know what I would have done if I had not encountered such a point like this. I’m able to at this moment look ahead to my future. Thanks for your time so much for this expert and amazing guide. I won’t hesitate to refer your blog post to any individual who needs to have recommendations on this area.

    回复 2019年10月24日
  8. air max 95

    I and my friends appeared to be following the good guidelines found on the blog and so all of a sudden got a horrible suspicion I had not thanked you for them. Most of the guys were definitely certainly excited to read through them and have in truth been tapping into those things. Thank you for being well accommodating and then for settling on variety of quality issues millions of individuals are really desperate to understand about. Our own sincere regret for not saying thanks to sooner.

    回复 2019年10月23日
  9. louboutin

    I want to show some thanks to this writer just for bailing me out of this circumstance. Just after surfing around through the search engines and getting techniques which were not powerful, I thought my entire life was well over. Existing without the strategies to the difficulties you’ve fixed by way of your main website is a critical case, and ones which might have adversely damaged my career if I had not discovered your web site. Your good mastery and kindness in maneuvering almost everything was valuable. I’m not sure what I would’ve done if I had not encountered such a point like this. I can also at this time look forward to my future. Thanks very much for the impressive and sensible help. I won’t hesitate to suggest your web sites to any individual who needs and wants guidance on this topic.

    回复 2019年10月23日
  10. longchamp outlet

    I wish to show my thanks to this writer for rescuing me from this scenario. After scouting throughout the online world and getting ideas which are not powerful, I believed my life was over. Living without the solutions to the problems you’ve fixed as a result of your review is a crucial case, and the kind which may have badly damaged my entire career if I hadn’t come across your web page. Your own personal know-how and kindness in dealing with all the stuff was very useful. I’m not sure what I would have done if I had not discovered such a solution like this. I’m able to now look forward to my future. Thanks very much for your high quality and result oriented help. I will not think twice to endorse the sites to any individual who should get guidelines about this situation.

    回复 2019年10月22日
  11. curry 4

    I am also writing to let you know what a excellent discovery my friend’s princess encountered viewing your site. She even learned several issues, not to mention how it is like to have an excellent helping spirit to get the rest clearly gain knowledge of chosen hard to do subject areas. You truly exceeded our expectations. I appreciate you for providing those beneficial, dependable, educational and even cool thoughts on your topic to Tanya.

    回复 2019年10月22日
  12. authentic jordans

    I and also my friends were looking at the nice guides located on your web site and then unexpectedly got an awful suspicion I never expressed respect to the blog owner for those tips. These ladies were certainly stimulated to learn them and have in fact been making the most of them. We appreciate you genuinely well considerate and also for figuring out this sort of good tips millions of individuals are really desirous to discover. My very own sincere regret for not expressing gratitude to sooner.

    回复 2019年10月21日
  13. paul george shoes

    I wish to show my appreciation to you for bailing me out of this type of scenario. Just after scouting through the internet and meeting proposals which are not powerful, I figured my entire life was well over. Existing without the approaches to the difficulties you have sorted out all through your good review is a crucial case, as well as those which might have in a negative way damaged my career if I had not discovered your web site. Your own personal capability and kindness in dealing with the whole thing was important. I’m not sure what I would’ve done if I had not encountered such a solution like this. It’s possible to at this moment relish my future. Thanks so much for the specialized and amazing help. I will not hesitate to propose your site to any person who needs counselling on this situation.

    回复 2019年10月20日
  14. hermes belt

    I wish to show thanks to this writer for rescuing me from such a incident. Right after browsing throughout the world wide web and obtaining strategies which are not pleasant, I was thinking my life was gone. Living without the solutions to the issues you have fixed by way of your site is a crucial case, as well as the kind which might have in a wrong way affected my career if I had not come across your web blog. That skills and kindness in maneuvering all areas was very helpful. I am not sure what I would have done if I hadn’t discovered such a step like this. It’s possible to at this time relish my future. Thanks a lot so much for your specialized and results-oriented help. I won’t be reluctant to recommend your blog to anybody who desires assistance about this issue.

    回复 2019年10月19日
  15. russell westbrook shoes

    I want to convey my passion for your kindness for those people who really need assistance with your area. Your personal dedication to passing the message all around was incredibly invaluable and has usually made women like me to achieve their goals. Your amazing insightful tutorial means much a person like me and a whole lot more to my peers. Many thanks; from all of us.

    回复 2019年10月18日
  16. yeezy shoes

    I am also commenting to make you understand what a cool discovery my friend’s princess undergone going through your web site. She figured out so many things, which included what it’s like to have an amazing giving spirit to have other folks without problems gain knowledge of several hard to do things. You undoubtedly surpassed her expected results. Thank you for distributing such precious, dependable, explanatory as well as fun tips about the topic to Emily.

    回复 2019年10月17日
  17. lebron shoes

    Thank you so much for giving everyone an exceptionally pleasant opportunity to read from here. It’s always very great and full of a good time for me and my office fellow workers to visit your website a minimum of 3 times a week to find out the fresh guides you will have. And lastly, we’re actually amazed with the magnificent suggestions you give. Some two points in this posting are particularly the simplest I’ve had.

    回复 2019年10月16日
  18. fila

    I would like to express my admiration for your generosity giving support to visitors who really need help with this one subject. Your personal dedication to getting the message all around became astonishingly important and have usually encouraged many people just like me to get to their pursuits. Your own important information signifies much to me and extremely more to my peers. Thanks a lot; from everyone of us.

    回复 2019年10月14日
  19. coach factory outlet

    Thanks so much for giving everyone such a superb opportunity to read in detail from this site. It’s always very ideal plus jam-packed with fun for me personally and my office friends to visit your website really 3 times weekly to read the latest issues you have. Of course, I’m also always amazed with the surprising points served by you. Some 2 areas in this posting are ultimately the simplest we have had.

    回复 2019年10月13日
  20. moncler

    I have to get across my gratitude for your kindness in support of women who have the need for assistance with this important theme. Your very own dedication to getting the message around appears to be extraordinarily productive and have continuously made employees like me to achieve their objectives. The insightful advice implies so much to me and a whole lot more to my office workers. Many thanks; from all of us.

    回复 2019年10月12日
  21. balenciaga shoes

    I wish to convey my love for your kind-heartedness for all those that really want help with this concept. Your very own dedication to getting the solution throughout came to be amazingly important and has continually allowed others much like me to achieve their dreams. Your amazing valuable guidelines means a whole lot a person like me and substantially more to my office colleagues. Regards; from everyone of us.

    回复 2019年10月11日
  22. moncler jackets

    I would like to express my appreciation to you for rescuing me from such a setting. After searching through the world wide web and finding things that were not pleasant, I figured my life was well over. Being alive without the solutions to the problems you’ve fixed as a result of your main posting is a serious case, as well as ones which may have in a wrong way affected my entire career if I had not noticed your web page. Your actual expertise and kindness in handling all the details was useful. I’m not sure what I would have done if I had not come upon such a point like this. I’m able to at this point look forward to my future. Thanks very much for your impressive and results-oriented help. I won’t think twice to suggest your web sites to anybody who should receive counselling on this issue.

    回复 2019年10月11日
  23. golden goose

    Thanks a lot for giving everyone an extremely memorable chance to read articles and blog posts from this blog. It is usually so pleasant plus jam-packed with a great time for me personally and my office colleagues to visit your website the equivalent of three times in a week to read through the newest guidance you have got. Not to mention, I’m always happy concerning the magnificent methods served by you. Some 2 points on this page are in reality the very best I have ever had.

    回复 2019年10月10日
  24. kyrie 5 shoes

    I needed to compose you the very small word so as to thank you so much as before for the spectacular pointers you’ve provided above. This is particularly generous of people like you to present extensively precisely what many people would have marketed as an ebook to help with making some profit for themselves, most notably considering the fact that you might have tried it in the event you wanted. The concepts likewise acted like a great way to comprehend many people have similar keenness really like mine to know great deal more with regard to this matter. I’m certain there are thousands of more enjoyable times up front for those who scan your blog post.

    回复 2019年10月9日
  25. birkin bag

    I precisely wanted to appreciate you once more. I’m not certain what I would have gone through in the absence of the entire information discussed by you concerning this concern. It became the depressing issue in my circumstances, however , being able to see a professional form you dealt with it took me to weep over joy. Extremely grateful for the guidance and then sincerely hope you find out what a powerful job that you’re doing teaching men and women using your webpage. Most probably you’ve never got to know any of us.

    回复 2019年10月8日