file_get_contents在生产服务器上不起作用,在本地上可以 [英] file_get_contents not working on production server, fine on local

查看:212
本文介绍了file_get_contents在生产服务器上不起作用,在本地上可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,可以从远程服务器获取图像,以便可以使用HTML5 canvas API对其进行操作.

I have a PHP script that fetches an image from a remote server so that I can manipulate it using HTML5 canvas API.

<?php
if ((isset($_GET['url']))) {
    $url = $_GET['url'];
    $file_format = pathinfo($url, PATHINFO_EXTENSION);
    try
    {   
        header("Content-Type: image/$file_format");
        header("Content-disposition: filename=image.$file_format");
        $img = file_get_contents($url);
        echo $img;
    }

    catch(Exception $e)
    {
        echo $e->getMessage();
    }
}

else die('Unknown request');
?>

典型请求如下所示:

fetch_image.php?url=http://example.com/images/image.png

在我的本地服务器上一切正常,但是生产服务器给我这个错误:

Everything works fine on my local server but the production server gives me this error:

NetworkError:500内部服务器错误.

NetworkError: 500 Internal Server Error.

错误日志记录以下消息:

The error log registers this message:

PHP警告:无法修改标头信息-标头已发送.

PHP Warning: Cannot modify header information - headers already sent.

我尝试了一些建议,但是没有用:

I have tried some of the suggestions but its not working:

allow_url_fopen = 1

推荐答案

检查服务器是否允许您使用文件功能打开远程URL(php.ini的"allow_url_fopen"设置必须为"true").

Check that the server allows you to open remote URLs with the file functions (the php.ini "allow_url_fopen" setting must be "true").

这篇关于file_get_contents在生产服务器上不起作用,在本地上可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆