问题
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