public function setUp() { Cloudinary::reset_config(); if (!Cloudinary::config_get("api_secret")) { $this->markTestSkipped('Please setup environment for Upload test to run'); } $this->tag = "php_test_" . time(); Cloudinary\Uploader::upload("tests/logo.png", array("tags" => array($this->tag))); Cloudinary\Uploader::upload("tests/logo.png", array("tags" => array($this->tag), "width" => 10, "crop" => "scale")); }
function upload_to_cdn($files) { try { if (isset($_POST['submit'])) { $cloud = new \Cloudinary\Uploader(); $result = (object) $cloud->upload($files, array("use_filename" => true)); if (!empty($result->signature)) { return array("status" => 1, "secure_url" => $result->secure_url, "f" => "generate"); } } } catch (Exception $e) { if (!empty($files)) { return array("status" => 0, "error_message" => $e->getMessage()); } return array("status" => 1, "f" => "default"); } }
* @param \Psr\Http\Message\UploadedFileInterface $photo * @param string[] $memberData * @return string[] */ return function (UploadedFileInterface $photo, $memberData) use($settings, $session) { if ($photo->getError() !== UPLOAD_ERR_OK) { return $memberData; } $allowedTypes = ['image/jpeg', 'image/png']; if (!in_array($photo->getClientMediaType(), $allowedTypes)) { throw new InvalidArgumentException('We only accept jpg and png image'); } $ext = strtolower(pathinfo($photo->getClientFilename(), PATHINFO_EXTENSION)); $cdnTargetPath = 'phpindonesia/' . $settings['mode'] . '/'; $newFileName = $session->get('user_id') . '-' . date('YmdHis'); Cloudinary\Uploader::upload($photo->file, ['public_id' => $cdnTargetPath . $newFileName, 'tags' => ['user-avatar']]); $memberData['photo'] = $newFileName . '.' . $ext; if ($session->get('photo')) { $api = new Cloudinary\Api(); $publicId = str_replace('.' . $ext, '', $session->get('photo')); $api->delete_resources($cdnTargetPath . $publicId, ['public_id' => $cdnTargetPath . $newFileName, 'tags' => ['user-avatar']]); $session->set('photo', $memberData['photo']); } return $memberData; }; }; /** * Setup mailer container * * TODO: will replaced with PHPMailer */
public function test_context() { //should allow sending context $context = array("caption" => "some caption", "alt" => "alternative"); $result = Cloudinary\Uploader::upload("tests/logo.png", array("context" => $context)); $api = new \Cloudinary\Api(); $info = $api->resource($result["public_id"], array("context" => true)); $this->assertEquals(array("custom" => $context), $info["context"]); }