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

福尔摩斯对我笑 2019-02-18 11168 次 1338条
应领导要求,对现有的文件访问进行权限控制,必须登录后才能直接访问文件。 之前做过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
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 1338 条评论 1


  1. cheap jordans

    I wanted to draft you the little bit of observation so as to say thanks a lot as before for all the nice advice you’ve contributed at this time. It has been simply strangely open-handed with people like you to present unreservedly what most people would’ve offered as an electronic book to end up making some dough for their own end, most importantly seeing that you could possibly have tried it if you ever decided. Those pointers additionally acted to be the good way to fully grasp that some people have a similar keenness like mine to know many more pertaining to this matter. I believe there are numerous more fun situations ahead for folks who view your blog.

    回复 2019年10月29日
  2. balenciaga

    I together with my guys have already been examining the good thoughts from your web blog then the sudden I had a horrible suspicion I never thanked the web site owner for those tips. These guys were definitely so thrilled to study them and have in reality been taking advantage of them. Appreciate your indeed being simply helpful as well as for picking these kinds of ideal guides most people are really wanting to understand about. Our own honest regret for not expressing appreciation to you sooner.

    回复 2019年10月29日
  3. hogan outlet

    I would like to express appreciation to the writer just for rescuing me from such a challenge. Just after searching throughout the the net and meeting methods which were not productive, I believed my life was well over. Existing devoid of the approaches to the problems you have solved by means of the review is a critical case, as well as the ones that would have negatively damaged my entire career if I hadn’t discovered your site. Your own capability and kindness in maneuvering all areas was priceless. I don’t know what I would’ve done if I hadn’t encountered such a subject like this. It’s possible to at this moment relish my future. Thanks a lot very much for your professional and effective guide. I will not think twice to propose your blog post to any individual who ought to have care on this topic.

    回复 2019年10月29日
  4. kobe byrant shoes

    I am just writing to let you know of the fabulous experience our daughter enjoyed reading through your blog. She discovered some details, which include what it’s like to have an ideal helping mood to let most people very easily grasp a number of specialized matters. You really did more than my expected results. I appreciate you for presenting these good, dependable, informative and as well as unique thoughts on your topic to Lizeth.

    回复 2019年10月28日
  5. vans shoes

    I simply needed to thank you so much once again. I do not know the things that I could possibly have used without the entire tips revealed by you concerning my industry. It has been a real frightening condition for me personally, however , looking at the very expert form you dealt with it forced me to leap with contentment. I’m happy for this assistance and thus have high hopes you find out what an amazing job your are undertaking teaching the rest through your site. Most probably you have never encountered any of us.

    回复 2019年10月28日
  6. yeezy boost 350 v2

    I intended to put you that very small observation to help give thanks the moment again over the unique tips you’ve shared on this site. It’s quite remarkably open-handed of you to deliver openly what exactly a lot of folks could possibly have sold as an e-book in making some profit for themselves, mostly now that you could have tried it if you decided. Those pointers likewise served like a great way to fully grasp that someone else have a similar interest like my personal own to realize a great deal more with respect to this problem. I think there are millions of more pleasant occasions in the future for many who check out your site.

    回复 2019年10月28日
  7. ferragamo belt

    Thanks a lot for giving everyone remarkably remarkable opportunity to read articles and blog posts from here. It’s always so pleasurable and also jam-packed with fun for me and my office acquaintances to visit your website no less than three times in 7 days to read the fresh stuff you have got. And lastly, I am also actually fulfilled with all the mind-blowing knowledge served by you. Selected 1 areas on this page are surely the most suitable we have ever had.

    回复 2019年10月28日
  8. nike off whtie

    I as well as my guys have already been reading through the good helpful tips found on your web blog and then got a horrible suspicion I never expressed respect to the web blog owner for those tips. All the people became warmed to see them and have in effect extremely been making the most of these things. Thank you for turning out to be so thoughtful as well as for selecting these kinds of very good ideas most people are really desirous to be informed on. My sincere regret for not saying thanks to earlier.

    回复 2019年10月27日
  9. outlet golden goose

    I would like to express some appreciation to you just for bailing me out of this type of instance. As a result of looking throughout the search engines and meeting concepts which were not powerful, I thought my entire life was over. Being alive without the presence of strategies to the issues you have sorted out as a result of your main blog post is a crucial case, and those that could have in a negative way affected my career if I had not discovered your web page. Your main capability and kindness in playing with everything was crucial. I don’t know what I would have done if I hadn’t encountered such a step like this. I can at this time relish my future. Thanks so much for this reliable and effective guide. I will not hesitate to recommend your web sites to any individual who desires guidelines about this subject.

    回复 2019年10月27日
  10. yeezy boost

    I would like to show my thanks to this writer for bailing me out of such a scenario. Because of looking out through the the web and finding advice which were not beneficial, I thought my life was well over. Existing without the presence of answers to the issues you have fixed all through your main report is a crucial case, and ones that could have in a wrong way damaged my entire career if I hadn’t discovered your blog. The knowledge and kindness in controlling everything was very useful. I’m not sure what I would have done if I hadn’t come across such a stuff like this. I am able to at this moment relish my future. Thank you very much for your high quality and results-oriented help. I will not think twice to suggest your web blog to any person who needs to have guidance about this subject matter.

    回复 2019年10月27日
  11. balenciaga shoes

    My wife and i were so joyful that Ervin could carry out his research via the precious recommendations he obtained in your web site. It’s not at all simplistic to simply happen to be offering tips and hints that many people might have been selling. So we grasp we have got you to give thanks to because of that. Most of the illustrations you made, the straightforward blog navigation, the friendships you can aid to instill – it’s got everything excellent, and it’s making our son in addition to our family understand the content is awesome, which is certainly unbelievably pressing. Thanks for everything!

    回复 2019年10月27日
  12. coach bags sale

    Thanks so much for providing individuals with a very brilliant possiblity to read critical reviews from this website. It can be so nice plus full of amusement for me and my office fellow workers to visit your web site nearly three times a week to find out the new stuff you have got. And lastly, I am always fascinated with your cool opinions served by you. Selected 1 areas in this post are undoubtedly the most effective we have ever had.

    回复 2019年10月26日
  13. kate spade handbags

    I precisely wanted to thank you so much once again. I’m not certain what I might have followed in the absence of the actual methods provided by you on my industry. It became the frightening issue in my opinion, nevertheless looking at your professional avenue you treated the issue took me to weep with happiness. I am just happier for the service and as well , have high hopes you really know what a powerful job that you’re undertaking instructing other individuals using your site. I’m certain you have never met all of us.

    回复 2019年10月26日
  14. 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日
  15. 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日
  16. 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日
  17. 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日
  18. 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日
  19. 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日
  20. 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日
  21. 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日
  22. 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日
  23. 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日
  24. 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日
  25. 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日
  26. 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日
  27. 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日
  28. 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日
  29. 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日
  30. 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日
  31. 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日
  32. 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日
  33. 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日
  34. 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日
  35. 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日
  36. 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日
  37. 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日
  38. 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日