use*_*493 16 php api plugins file-get-contents web-development-server
我正试图在xampp服务器上的网站上使用php脚本从服务器下载图像.
正在使用函数file_get_contents下载映像.
在服务器上下载的php代码是:
if(isset($_GET['path']) && isset($_GET['username'])) {
echo "path:".$_GET['path'];
$temp = explode(".", $_GET['path']);
$extension = end($temp);
$fname="images/".$_GET['title'];
$filenameIn = $_GET['path'];
$filenameOut = "" . $fname;
$contentOrFalseOnFailure = file_get_contents($filenameIn);
$byteCountOrFalseOnFailure = file_put_contents($filenameOut,$contentOrFalseOnFailure);
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
警告:file_get_contents():php_network_getaddresses:getaddrinfo failed:第19行的/opt/lampp/htdocs/xampp/project/upload_art.php中未知的名称或服务
警告:file_get_contents(http://app6.pixlr.com/_temp/528afa6e2f7cc6a5b1000101.jpg):无法打开流:php_network_getaddresses:getaddrinfo failed:/ opt/lampp/htdocs/xampp/project/upload_art中未知名称或服务.第19行的PHP
我已经检查了所有发布的答案,但似乎没有解决问题.请帮忙!
Sir*_*han 21
这意味着您的服务器无法连接到外部世界
鉴于DNS问题,这可能不会改变任何事情
因此,如果您有权限,请尝试将/etc/resolv.conf文件中的名称服务器更改为其他名称服务器.
小智 11
应该有httpd允许连接外部.检查你的selinux政策.这有助于我解决连接问题:
setsebool -P nis_enabled 1
setsebool -P httpd_can_network_connect 1
Run Code Online (Sandbox Code Playgroud)
参考@DUzun 的评论之一,对于像我这样熟悉服务器但不是计算机科学专业的人,我通过以下方式修复了Linux/Centos6 (Plesk Onyx) 上的问题:
1)打开/etc/resolv.conf
(我的文件是空的)
2) 新增:
nameserver 8.8.8.8
nameserver 8.8.4.4
options rotate
options timeout:3
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助那里的人。