file_get_contents():php_network_getaddresses:

我正在尝试使用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);

}

但我收到此错误:


警告:file_get_contents():php_network_getaddresses:getaddrinfo失败:在第19行的/opt/lampp/htdocs/xampp/project/upload_art.php中名称或服务未知


警告:file_get_contents(http://app6.pixlr.com/_temp/528afa6e2f7cc6a5b1000101.jpg):无法打开流:php_network_getaddresses:getaddrinfo失败:在/ opt / lampp / htdocs / xampp / project / upload_art中未知的名称或服务。第19行的php


我已经在这里签出了所有已发布的答案,但似乎没有一个可以解决该问题。请帮忙!


慕容708150
浏览 1253回答 3
3回答

不负相思意

这意味着您的服务器无法连接到外部世界鉴于DNS问题,这可能不会改变任何内容因此,如果您有权限,请尝试将/etc/resolv.conf文件中的名称服务器更改为其他名称服务器。

catspeake

还应该允许httpd连接到外部。检查您的selinux策略。这可以帮助我解决连接问题:setsebool -P nis_enabled 1setsebool -P httpd_can_network_connect 1

慕侠2389804

如果您将Docker env用于您的Web应用程序,则提供以下建议。我在使用docker php映像时遇到了同样的问题,在yml文件中添加了dns选项解决了我的问题。docker-compose.ymlversion: '2'services:  webserver:    build: ./docker/webserver    image: my_webapp    dns: 8.8.8.8    dns_opt:      - use-vc      - no-tld-query    ports:      - 80:80      - 443:443    volumes:      - ./:/var/www/html
打开App,查看更多内容
随时随地看视频慕课网APP