Aviary jquery将表单变量传递给post url

时间:2013-09-27 16:41:48

标签: php jquery aviary

我正在尝试使用鸟舍发送图像名称,并且需要包含图像名称。我的表单中有一个隐藏字段“img”这是代码:

 <script type='text/javascript'>
 var featherEditor = new Aviary.Feather({
 apiKey: 'yogbsxxxxxxxx4',
 apiVersion: 3,

 theme: 'dark', // Check out our new 'light' and 'dark' themes!
 tools: 'enhance,crop,orientation,brightness,sharpness,redeye,resize,text',
 appendTo: '',
 onSave: function(imageID, newURL) {
 var img = document.getElementById(imageID);
 img.src = newURL;

 },
 onError: function(errorObj) {
 alert(errorObj.message);
 },
 postUrl: 'http://xxxxx/~gsidev/gallery/post.php',
 postData : document.getElementById(img),// this is the field I need and does not work?

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

感谢您提供任何指导。在Aviary上支持php实现很糟糕......

1 个答案:

答案 0 :(得分:1)

想出来!我添加了一个新变量并传递了它。这将在php中发送文件名并覆盖现有文件,提供您的post url文件与您为编辑器调用的图像位于同一文件夹中。

  function launchEditor(id, src, img) {
  featherEditor.launch({
  image: id,
  url: src,
 postData : img
   });
  return false;
  }
  </script>

现在在保存页面上:      

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

    file_put_contents(($_REQUEST['postData']),$image_data);

 ?>

并更改链接或按钮代码以匹配

 <!-- Add an edit button, passing the HTML id of the image
     and the public URL to the image -->
  <a href="#" onclick="return launchEditor('editableimage1',"imagename.jpg" 
     'http://example.com/public/images/goat.jpg');">Edit!</a>