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

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

发表评论



 


已有 725 条评论 1


  1. Click Here

    Spot on with this write-up, I seriously feel this site needs far more attention. I’ll probably be returning to see more, thanks for the info!

    回复 2020年2月26日
  2. Abbruch aus Lübeck

    Very good post! We will be linking to this particularly great post on our site. Keep up the good writing.

    回复 2020年2月26日
  3. Rain Go Gutters Raleigh NC

    Howdy! This blog post couldn’t be written any better! Going through this post reminds me of my previous roommate! He constantly kept preaching about this. I’ll forward this post to him. Pretty sure he’ll have a good read. Thank you for sharing!

    回复 2020年2月26日
  4. Ontario Lottery

    I’m amazed, I must say. Rarely do I encounter a blog that’s equally educative and entertaining, and without a doubt, you have hit the nail on the head. The issue is something which not enough people are speaking intelligently about. I am very happy I came across this during my hunt for something regarding this.

    回复 2020年2月25日
  5. modern construction industry

    Hi there! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back frequently!

    回复 2020年2月25日
  6. tc bolts

    Hey there! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a outstanding job!

    回复 2020年2月25日
  7. Fayetteville NC Home Inspector

    It’s hard to come by educated people about this topic, but you sound like you know what you’re talking about! Thanks

    回复 2020年2月25日
  8. f1852 tc bolts

    Hi there are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you require any html coding expertise to make your own blog? Any help would be really appreciated!

    回复 2020年2月25日
  9. Professional Junk Removal Raleigh NC

    It’s difficult to find well-informed people on this topic, however, you sound like you know what you’re talking about! Thanks

    回复 2020年2月25日
  10. Best egusi soup in La

    After going over a number of the blog articles on your web page, I truly appreciate your technique of blogging. I book-marked it to my bookmark site list and will be checking back soon. Please check out my website too and let me know how you feel.

    回复 2020年2月25日
  11. Best egusi soup in La

    You have made some decent points there. I looked on the internet for more information about the issue and found most individuals will go along with your views on this website.

    回复 2020年2月25日
  12. CBD

    I really love your blog.. Very nice colors & theme. Did you create this website yourself? Please reply back as I’m trying to create my own blog and would love to know where you got this from or what the theme is named. Many thanks.

    回复 2020年2月25日
  13. Jaisalmer escorts service

    I truly appreciate this post. I’ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!

    回复 2020年2月25日
  14. buy weed in uk

    Wow! This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Actually Excellent. I am also an expert in this topic therefore I can understand your hard work.

    回复 2020年2月25日
  15. superb maid

    Greetings! I know this is somewhat off topic but I was wondering which blog platform are you using for this site? I’m getting fed up of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.

    回复 2020年2月25日
  16. read more

    I love it when folks come together and share thoughts. Great site, keep it up!

    回复 2020年2月25日
  17. rachel cusk on becoming a mother

    Have you ever thought about writing an ebook or guest authoring on other sites? I have a blog based on the same topics you discuss and would really like to have you share some stories/information. I know my audience would value your work. If you are even remotely interested, feel free to send me an e-mail.

    回复 2020年2月25日
  18. maid service las vegas

    First of all I want to say wonderful blog! I had a quick question which I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your mind prior to writing. I’ve had a tough time clearing my thoughts in getting my ideas out there. I do enjoy writing however it just seems like the first 10 to 15 minutes are generally wasted just trying to figure out how to begin. Any ideas or hints? Many thanks!

    回复 2020年2月24日
  19. click here

    Right here is the perfect web site for anyone who wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I really would want to…HaHa). You certainly put a brand new spin on a topic which has been discussed for ages. Excellent stuff, just wonderful.

    回复 2020年2月24日
  20. Silver spring Braiding salon

    You have remarked very interesting points ! ps decent internet site . “I hate music, especially when it’s played.” by Jimmy Durante.

    回复 2020年2月24日
  21. read more

    An impressive share! I have just forwarded this onto a colleague who had been doing a little research on this. And he actually bought me breakfast due to the fact that I stumbled upon it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanx for spending some time to discuss this issue here on your blog.

    回复 2020年2月24日
  22. สล็อตออนไลน์

    Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs and related information ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, web site theme . a tones way for your client to communicate. Excellent task..

    回复 2020年2月24日
  23. kyrie spongebob

    I would like to show my respect for your kindness in support of people that actually need assistance with that question. Your personal dedication to passing the solution throughout had become definitely helpful and has in every case enabled some individuals much like me to achieve their ambitions. The warm and friendly tutorial denotes much to me and further more to my colleagues. Thank you; from all of us.

    回复 2020年2月24日
  24. mobil bahis sitesi

    A formidable share, I simply given this onto a colleague who was doing somewhat evaluation on this. And he in reality bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying extra on this topic. If attainable, as you turn into experience, would you mind updating your weblog with extra details? It’s extremely helpful for me. Large thumb up for this weblog put up!

    回复 2020年2月23日
  25. betgram

    Oh my goodness! a tremendous article dude. Thank you Nevertheless I am experiencing subject with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting an identical rss problem? Anyone who is aware of kindly respond. Thnkx

    回复 2020年2月23日
  26. Chinese medicine

    I enjoy looking through an article that can make people think. Also, thank you for allowing for me to comment.

    回复 2020年2月23日
  27. super peach wear

    A motivating discussion is worth comment. I think that you need to write more on this issue, it might not be a taboo subject but generally folks don’t discuss these issues. To the next! Best wishes.

    回复 2020年2月23日
  28. notebook

    Aw, this was an incredibly good post. Taking the time and actual effort to produce a good article… but what can I say… I hesitate a whole lot and never seem to get nearly anything done.

    回复 2020年2月23日
  29. https://cashdomino88.com

    I like what you guys are up too. Such clever work and reporting! Carry on the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my site 🙂

    回复 2020年2月23日
  30. seo service

    Keep working ,terrific job!

    回复 2020年2月23日
  31. Bike helmet

    Excellent article! We are linking to this particularly great content on our website. Keep up the great writing.

    回复 2020年2月23日
  32. Rose Blad

    This writing article support review is basically standard. This review is extremely useful to students accumulated some essay writing details for good essay. Such a essay writing articles are extremely impressive in order to viewers. Thank you pertaining to sharing your notions. anchor |

    回复 2020年2月23日
  33. crazy bulk avis

    I could not refrain from commenting. Perfectly written.

    回复 2020年2月22日
  34. John Deere Technical Manuals

    Great post, I conceive blog owners should acquire a lot from this web blog its real user pleasant.

    回复 2020年2月22日
  35. CBD products

    It¡¦s really a great and useful piece of information. I am satisfied that you just shared this useful information with us. Please stay us up to date like this. Thanks for sharing.

    回复 2020年2月22日
  36. DC furniture assembly

    As a Newbie, I am continuously browsing online for articles that can benefit me. Thank you

    回复 2020年2月22日
  37. Silver spring Movers

    You must participate in a contest for one of the best blogs on the web. I’ll recommend this site!

    回复 2020年2月22日
  38. Buy Phone Battery Online

    I got what you mean , regards for posting .Woh I am lucky to find this website through google. “The test and use of a man’s education is that he finds pleasure in the exercise of his mind.” by Carl Barzun.

    回复 2020年2月22日
  39. Legal justice Advocates

    Oh my goodness! Incredible article dude! Many thanks, However I am encountering difficulties with your RSS. I don’t understand why I am unable to subscribe to it. Is there anybody else getting the same RSS problems? Anybody who knows the solution can you kindly respond? Thanx.

    回复 2020年2月21日
  40. gtarealstar

    This website truly has all of the information and facts I wanted about this subject and didn’t know who to ask.

    回复 2020年2月21日
  41. FabFilter Crack

    Nice post. I learn something new and challenging on sites I stumbleupon everyday. It’s always helpful to read through articles from other authors and use a little something from their sites.

    回复 2020年2月21日
  42. supreme clothing

    I together with my guys have been examining the best tips on your web page while the sudden got a horrible suspicion I never thanked the web blog owner for those tips. Those boys were definitely excited to read through all of them and already have definitely been loving these things. Many thanks for being quite kind and for having these kinds of incredibly good subject areas most people are really eager to be aware of. My personal honest regret for not expressing gratitude to earlier.

    回复 2020年2月21日
  43. fruit seeds

    Aw, this was an exceptionally good post. Finding the time and actual effort to generate a top notch article… but what can I say… I put things off a whole lot and never seem to get nearly anything done.

    回复 2020年2月21日
  44. Bowie Braiding salon

    Hey there, You’ve done a great job. I will definitely digg it and personally recommend to my friends. I’m confident they’ll be benefited from this website.

    回复 2020年2月21日
  45. Virginia Furniture installers

    Thank you for sharing superb informations. Your site is very cool. I am impressed by the details that you have on this website. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched everywhere and simply couldn’t come across. What a perfect web site.

    回复 2020年2月21日
  46. DC Furniture assembly

    I wish to point out my appreciation for your generosity in support of women who require assistance with this one idea. Your real commitment to passing the solution all around appears to be exceptionally significant and has surely encouraged individuals like me to realize their targets. This warm and helpful guide indicates so much to me and far more to my peers. Warm regards; from everyone of us.

    回复 2020年2月21日
  47. dotafrog

    Hey very nice site!! Man .. Excellent .. Amazing .. I will bookmark your site and take the feeds also…I am happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

    回复 2020年2月20日
  48. sarasota movers

    You are my intake, I possess few blogs and rarely run out from post :). “Actions lie louder than words.” by Carolyn Wells.

    回复 2020年2月20日
  49. best dentistry university schools nigeria

    I could not resist commenting. Exceptionally well written!

    回复 2020年2月19日
  50. mobil bahis bonus

    Good info. Lucky me I recently found your website by chance (stumbleupon). I’ve book-marked it for later!

    回复 2020年2月19日