1

我已将 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

有任何想法吗?

4

3 回答 3

0

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

于 2014-09-22T20:07:59.780 回答
0

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

如果它的值是 1file_get_contents不能工作

在这种情况下,您可以使用 curl

于 2013-09-24T12:35:10.373 回答
0

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

在你的 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 '

线这样做

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

于 2016-01-27T14:24:42.287 回答