简体   繁体   English

Cloudinary如何在php中生成签名

[英]Cloudinary how generate signature in php

this is my code about cloudinary upload through widget, unfortunately i get upload error...i'm working on localhost, and the page where is placed this code is add.php page 这是关于通过小部件进行cloudinary上传的代码,遗憾的是我收到了上传错误...我正在使用localhost,并且放置此代码的页面是add.php页面

<script src="//widget.cloudinary.com/global/all.js" type="text/javascript"></script>
<script type="text/javascript">
  var generateSignature = function(callback, params_to_sign){
    $.ajax({
      url     : "http://localhost/add.php?public_id=sample_image&timestamp=1315060510",
      type    : "GET",
      dataType: "text",
      data    : { data: params_to_sign},
      complete: function() {console.log("complete")},
      success : function(signature, textStatus, xhr) { callback(signature); },
      error   : function(xhr, status, error) { console.log(xhr, status, error); }
    });
  }
</script>


    <script type="text/javascript">  
      $('#upload_widget_opener').cloudinary_upload_widget(
        { cloud_name: 'dammiunparere', api_key: '189XXXX42445355',
          upload_signature: generateSignature},

        function(error, result) { console.log(error, result) });
    </script>

Recently tried to sort out with this question. 最近试图解决这个问题。 Here is simple solution: 这是简单的解决方案:

It needs to have script on your server to generate signature, in this case it is file named "add.php". 它需要在您的服务器上有脚本来生成签名,在这种情况下,它是名为“add.php”的文件。 It should contain something like: 它应该包含以下内容:

<?php
    define('CINCDIR', './inc/cloudinary/'); // path to cloudinary lib folder

    require_once(CINCDIR . 'Cloudinary.php');
    require_once(CINCDIR . 'Api.php');

    if(isset($_GET['data']))
    {
        echo \Cloudinary::api_sign_request($_GET['data'], '[PUT CLOUDINARY API SECRET HERE]');
    }
?>

Replace [PUT CLOUDINARY API SECRET HERE] with your cloudinary api secret. 用您的cloudinary api秘密替换[PUT CLOUDINARY API SECRET HERE]

This script needs cloudinary's PHP integration library. 这个脚本需要cloudinary的PHP集成库。 You should be able to download it from the following link: https://github.com/cloudinary/cloudinary_php/tarball/master . 您应该可以从以下链接下载它: https//github.com/cloudinary/cloudinary_php/tarball/master Copy all files from the src folder into your PHP project and include Cloudinary's PHP classes in your code: 将所有文件从src文件夹复制到PHP项目中,并在代码中包含Cloudinary的PHP类:

require_once(CINCDIR . 'Cloudinary.php');
require_once(CINCDIR . 'Api.php');

Also, about JavaScript from your example above, you don't need to pass predefined parameters here: 另外,关于上面示例中的JavaScript,您不需要在此处传递预定义参数:

url     : "http://localhost/add.php?public_id=sample_image&timestamp=1315060510"

Just URL of your script, in this case it is " http://localhost/add.php ": 只是脚本的URL,在这种情况下它是“ http://localhost/add.php ”:

url     : "http://localhost/add.php"

Parameters added automatically, when generateSignature function is called. 调用generateSignature函数时自动添加参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM