【发布时间】:2015-11-22 01:13:44
【问题描述】:
我正在尝试包含网页的内容,它在 localhost 上运行良好,但是当我将文件上传到服务器时它不再运行
我试过file_get_contents()、cURL、fopen,它们在我的电脑上都可以正常工作,但在网上失败了。
我的主机设置了 PHP.ini 中的变量来阻止我获取其他页面的内容吗?
<?php
$url = 'http://www.example.com';
echo stream_get_contents( fopen($url, 'r') );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
echo file_get_contents( $url );
?>
错误:
警告:fopen(http://www.example.com):打开流失败:网络 在 /srv/disk12/1999559/www/techmex.co.nf/test.php 上无法访问 第 6 行
警告:stream_get_contents() 期望参数 1 是资源, /srv/disk12/1999559/www/techmex.co.nf/test.php 中给出的布尔值 第 6 行
警告:file_get_contents(http://www.example.com):打开失败 流:网络无法访问 /srv/disk12/1999559/www/techmex.co.nf/test.php 第 17 行
【问题讨论】:
标签: php curl file-get-contents