file_get_contents() PHP 函数无法在 windows 服务器 运行 apache 上运行
file_get_contents() PHP function not working on windows server running apache
所以我有一个 运行ning windows 服务器,它 运行ning PHP 环境到 运行 一个博客网站。
现在以下代码 运行 在我的本地主机上使用 xampp 没问题,但在 windows 服务器上不起作用。
$image = get_the_post_thumbnail_url($postId, array(150,150));
$ext = pathinfo($image, PATHINFO_EXTENSION);
$base64 = 'data:image/' . $ext . ';base64,' . base64_encode(file_get_contents($image));
代码从循环中获取 post 缩略图并创建一个 base64 图像,我将其用于模糊图像技术(就像前两个图像发生的情况 on this site)
当我回显 $ext
和 $image
变量时,我得到了数据,但是当我回显 file_get_contents($image)
时,我什么也得不到。我可以确认该文件确实存在。
echo $ext . ':' . $image;
echo '<br />' . file_get_contents($image);
我看到了 allow_url_fopen
的建议,但是当我通过回显 phpinfo()
检查时,它已启用
echo phpinfo();
php 版本是 5.6,所以这也不是问题。
此外,当我为 windows 服务器打开 wordpress 调试时,我收到此错误:警告:file_get_contents():php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。
任何人都知道导致此问题的其他潜在原因。
干杯
天哪,我明白了。
windows服务器是测试站点,有urlhttps://test.domain.com.au
子域也是如此。
所以当我更新我的代码以在 url 中用 www 替换测试时,它起作用了。
$base64 = 'data:image/' . $ext . ';base64,' . base64_encode(file_get_contents(str_replace('test', 'www', $image)));
因此,即使图像 url https://test.domain.com.au/blog/wp-content/uploads/2017/03/my-image-150x150.jpg 是有效的 url 并且在粘贴到浏览器地址栏时显示图像,file_get_contents()
函数也没有不喜欢
不知道为什么会这样,因为测试站点是一个实时站点,所以像在 Internet 上一样实时。
我希望这对其他人有帮助:)
所以我有一个 运行ning windows 服务器,它 运行ning PHP 环境到 运行 一个博客网站。
现在以下代码 运行 在我的本地主机上使用 xampp 没问题,但在 windows 服务器上不起作用。
$image = get_the_post_thumbnail_url($postId, array(150,150));
$ext = pathinfo($image, PATHINFO_EXTENSION);
$base64 = 'data:image/' . $ext . ';base64,' . base64_encode(file_get_contents($image));
代码从循环中获取 post 缩略图并创建一个 base64 图像,我将其用于模糊图像技术(就像前两个图像发生的情况 on this site)
当我回显 $ext
和 $image
变量时,我得到了数据,但是当我回显 file_get_contents($image)
时,我什么也得不到。我可以确认该文件确实存在。
echo $ext . ':' . $image;
echo '<br />' . file_get_contents($image);
我看到了 allow_url_fopen
的建议,但是当我通过回显 phpinfo()
检查时,它已启用
echo phpinfo();
php 版本是 5.6,所以这也不是问题。
此外,当我为 windows 服务器打开 wordpress 调试时,我收到此错误:警告:file_get_contents():php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。
任何人都知道导致此问题的其他潜在原因。 干杯
天哪,我明白了。
windows服务器是测试站点,有urlhttps://test.domain.com.au 子域也是如此。
所以当我更新我的代码以在 url 中用 www 替换测试时,它起作用了。
$base64 = 'data:image/' . $ext . ';base64,' . base64_encode(file_get_contents(str_replace('test', 'www', $image)));
因此,即使图像 url https://test.domain.com.au/blog/wp-content/uploads/2017/03/my-image-150x150.jpg 是有效的 url 并且在粘贴到浏览器地址栏时显示图像,file_get_contents()
函数也没有不喜欢
不知道为什么会这样,因为测试站点是一个实时站点,所以像在 Internet 上一样实时。
我希望这对其他人有帮助:)