Example #1
1
 function cl_form_tag($callback_url, $options = array())
 {
     $form_options = Cloudinary::option_get($options, "form", array());
     $options["callback_url"] = $callback_url;
     $params = Cloudinary\Uploader::build_upload_params($options);
     $params = Cloudinary::sign_request($params, $options);
     $api_url = Cloudinary::cloudinary_api_url("upload", $options);
     $form = "<form enctype='multipart/form-data' action='" . $api_url . "' method='POST' " . Cloudinary::html_attrs($form_options) . ">\n";
     foreach ($params as $key => $value) {
         $form .= "<input " . Cloudinary::html_attrs(array("name" => $key, "value" => $value, "type" => "hidden")) . "/>\n";
     }
     $form .= "</form>\n";
     return $form;
 }
Example #2
0
 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
 */
Example #4
0
 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"]);
 }
Example #5
0
 public function test_create_zip()
 {
     $result = Cloudinary\Uploader::create_zip(array("tags" => $this->tag));
     $this->assertEquals(2, $result["file_count"]);
 }