使用file_get_contents打开文件时权限被拒绝;网络浏览器可以毫无问题地打开它


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

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

警告:file_get_contents(( [function.file-get-content]:connect(( 失败:文件名中的权限被拒绝.php在第 1

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

为什么我的浏览器可以打开文本文件,而file_get_contents()不能?

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

我也有类似的问题。 事实证明,这是我服务器上的SELinux的问题:

我从终端运行了这条线来重新关注它:

setsebool -P httpd_can_network_connect on

你能尝试像这样使用readfile函数,看看它是否获取文件内容:

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