function test_upload_preset() { // should support unsigned uploading using presets $api = new \Cloudinary\Api(); $preset = $api->create_upload_preset(array("folder" => "upload_folder", "unsigned" => TRUE)); $result = \Cloudinary\Uploader::unsigned_upload("tests/logo.png", $preset["name"]); $this->assertRegExp('/^upload_folder\\/[a-z0-9]+$/', $result["public_id"]); $api->delete_upload_preset($preset["name"]); }
<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::config_get("api_key") . Cloudinary::config_get("api_secret")), 0, 10); try { $api->upload_preset($upload_preset); } catch (\Cloudinary\Api\NotFound $e) { $api->create_upload_preset(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 echo !$unsigned; ?> "><?php echo $unsigned ? "Use signed upload" : "Use unsigned upload";