使用file_get_contents打开文件时,权限被拒绝;网页浏览器可以毫无问题地打开它 [英] Permission denied when opening file with file_get_contents; webbrowser can open it without problems

查看:1407
本文介绍了使用file_get_contents打开文件时,权限被拒绝;网页浏览器可以毫无问题地打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 file_get_contents()获取FTP服务器上文本文件的内容 ftp://ipaddress/somefile.txt ,我收到以下错误:


警告:file_get_contents()[ function.file-get-contents ]:connect()failed:Permission denied in < 1>


但是当我访问 ftp ://ipaddress/somefile.txt 在我的浏览器中,这绝对没有问题。



为什么我的浏览器可以打开文本文件,但可以使用 file_get_contents()不是?



PS:我不知道它是否与它有关,但ini指令 allow_url_fopen

有类似的问题。原来,这是我的服务器上的SELinux问题:



我从终端运行这条线以重新使用它:

  setsebool -P httpd_can_network_connect on 


When using file_get_contents() to get the file contents of a text file on an FTP server at ftp://ipaddress/somefile.txt, I'm getting the following error:

Warning: file_get_contents() [function.file-get-contents]: connect() failed: Permission denied in filename.php on line 1

But when I access ftp://ipaddress/somefile.txt within my webbrowser, it's absolutely no problem.

Why can my browser open the text file, but can file_get_contents() not?

PS: I don't know if it has something to do with it, but the ini directive allow_url_fopen is on.

解决方案

I had a similar problem. Turns out it was a problem with SELinux on my server:

I ran this line from the terminal to reslove it:

setsebool -P httpd_can_network_connect on

这篇关于使用file_get_contents打开文件时,权限被拒绝;网页浏览器可以毫无问题地打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆