<?php $unsigned = isset($_GET["unsigned"]) && $_GET["unsigned"] == "1"; ?> <div id='direct_upload'> <h1>Direct <?php if ($unsigned) { echo "unsigned "; } ?> upload from the browser</h1> <form> <?php if ($unsigned) { # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. $api = new \Cloudinary\Api(); $upload_preset = "sample_" . substr(sha1(\Cloudinary\Cloudinary::configGet("api_key") . \Cloudinary\Cloudinary::configGet("api_secret")), 0, 10); try { $api->uploadPreset($upload_preset); } catch (\Cloudinary\Api\NotFound $e) { $api->createUploadPreset(array("name" => $upload_preset, "unsigned" => TRUE, "folder" => "preset_folder")); } # The callback URL is set to point to an HTML file on the local server which works-around restrictions # in older browsers (e.g., IE) which don't full support CORS. echo cl_unsigned_image_upload_tag('test', $upload_preset, array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true))); } else { # The callback URL is set to point to an HTML file on the local server which works-around restrictions # in older browsers (e.g., IE) which don't full support CORS. echo cl_image_upload_tag('test', array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true))); } ?> <a href="?unsigned=<?php
<?php require 'main.php'; # You can add here your custom verification code # Check for a valid Cloudinary response $api_secret = \Cloudinary\Cloudinary::configGet("api_secret"); if (!$api_secret) { throw new \InvalidArgumentException("Must supply api_secret"); } $existing_signature = \Cloudinary\Cloudinary::optionConsume($_POST, "signature"); $to_sign = array('public_id' => $_POST['public_id'], 'version' => $_POST['version']); $calculated_signature = \Cloudinary\Cloudinary::apiSignRequest($to_sign, $api_secret); if ($existing_signature == $calculated_signature) { # Create a model record using the data received (best practice is to save locally # only data needed for reaching the image on Cloudinary - public_id and version; # and fields that might be needed for your application (e.g.,), width, height) $photo = \PhotoAlbum\create_photo_model($_POST); } else { error_log("Received signature verficiation failed (" . $existing_signature . " != " . $calculated_signature . "). data: " . \PhotoAlbum\ret_var_dump($_POST)); }