Permission denied when opening file with file_get_contents; webbrowser can open it without problems

久未见 提交于 2019-12-25 01:44:58

问题


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.


回答1:


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



回答2:


Can you try to use readfile function like this and see if this gets the file contents:

readfile('ftp://anonymous:email@example.com@' . $ipAddress . '/somefile.txt');


来源:https://stackoverflow.com/questions/10414208/permission-denied-when-opening-file-with-file-get-contents-webbrowser-can-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!