【问题标题】:file_get_contents error whilst using aviary使用 aviary 时出现 file_get_contents 错误
【发布时间】:2013-09-24 12:26:40
【问题描述】:

我已将 aviary 嵌入到我的网页中,它工作正常,但我无法使用 file_get_contents 命令来获取保存的图像。

鸟舍代码:

JS:

<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>

<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
    apiKey: '*********',
    apiVersion: 3,
    theme: 'light', // Check out our new 'light' and 'dark' themes!
    tools: 'crop,orientation,brightness,sharpness,redeye,effects,stickers,focus,contrast,whiten,warmth,colorsplash,enhance,saturation,blemish,draw,text,frames',
    appendTo: '',

    onSave: function(imageID, newURL) {
        var img = document.getElementById(imageID);
        img.src = newURL;       
    },           

    onError: function(errorObj) {
        alert(errorObj.message);
    },

    postUrl: 'http://example.com/featherposturl'      
});

function launchEditor(id, src) {
    featherEditor.launch({
        image: id,
        url: src
    });
    return false;
}

HTML:

<div id='injection_site'></div>

<img id='image1' src='photo.jpg' style="max-height:360px;" on/>

<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('image1', document.getElementById('image1').src);"/></p>

根据 aviary 文档,我可以获取已在 aviary 服务器上创建的临时文件,但使用以下 php 代码:

<?php

    $image_data = file_get_contents($_REQUEST['url']);

    file_put_contents("photo.jpg",$image_data);

?>

当我运行它时,它会出现此错误

[24-Sep-2013 12:14:16 UTC] PHP 警告:file_get_contents() [function.file-get-contents]:文件名不能为空......

有没有人知道如何获取在 aviary 服务器上创建的文件并将副本上传到我的服务器。

更新 我注意到一个名为“photo.jpg”的文件被添加到服务器中,文件大小为 0kb。我假设这是来自file_put_contents("photo.jpg",$image_data); 但图像数据是空白的,因为如果 file_get_contents 出现这是错误

有什么想法吗?

【问题讨论】:

  • file_get_contents 是 file_put_contents 上面的那一行

标签: javascript php jquery aviary


【解决方案1】:

请在您的服务器上检查allow_url_fopen = 0

如果它的值为 1 file_get_contents 就不能工作

这种情况下你可以使用 curl

【讨论】:

  • 根据我的phpinfo文件allow_url_fopen在Local和Master中设置为'on'
  • 文件 'photo.jpg' 正在上传到服务器,但文件大小为 0kb,所以有些东西正在工作,但我只是不完全理解代码
【解决方案2】:

Aviary 将回传到您选择的 URL,并带有指向保存在其服务器上的文件的链接。因此,您需要使用上面的服务器端代码 sn-p 在您的服务器上添加一个路由,并确保您指定的 postUrl 是您服务器上将调用此代码的 URL。

【讨论】:

    【解决方案3】:

    我有同样的问题,这个答案现在可能有点晚了,但我是这样解决的。这不是最好的方法,但确实有效

    在你的 javascript 中改变这个:

    onSave: function(imageID, newURL) {
            var img = document.getElementById(imageID);
            img.src = newURL;       
        },
    

    到这个:

    onSave: function(imageID, newURL) {
            var img = document.getElementById(imageID);
            img.src = newURL;
            var old_image = $('#oldimage').val(); //this is a hidden field with the HTML LINK for the original image on your server
            $.ajax({
                url : 'PHP Processing page',
                type : 'POST',
                dataType : 'JSON',
                data : {oldimage : old_image, newimage : img.src},
                success : function (json) {
                    console.log(json);
                }
            }); 
        }
    

    HTML:

    <input id="oldimage" type="hidden" value="ORIGINAL IMAGE" />
    <button class="button special fit" onclick="return launchEditor('image1', 'ORIGINAL IMAGE');">Edit This Image</button>
    

    在PHP处理页面中:

    $default = getenv("DOCUMENT_ROOT");
    define("SITEROOT",$default."/yoursite/");
    define("SITEHTMLROOT", "http//www.yoursite.com/");
    
    $oldimage = str_replace(SITEHTMLROOT, SITEROOT, $_POST['oldimage']);
    $newimage = $_POST['newimage'];
    copy($newimage, $oldimage);
    

    只要将 allow_url_fopen 设置为 on/1 就可以了

    你不需要添加

    postUrl: 'http://example.com/featherposturl'

    这样操作的行

    由于这篇文章很老了,如果您确实找到了这样做的好方法,您会分享它吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多