function ConvertToDB($arProperty, $value) { $value = $value['VALUE']; if (!$value) { return array('VALUE' => ''); } if (strpos($value, 'ucarecdn.com')) { $parts = parse_url($value); $path = $parts['path']; $path_parts = explode('/', $path); $file_id = $path_parts[1]; } else { $file_id = $value; } $public_key = COption::GetOptionString("uploadcare", "publickey"); $secret_key = COption::GetOptionString("uploadcare", "secretkey"); $uploadcare_api = new Uploadcare_Api($public_key, $secret_key); $file = $uploadcare_api->getFile($file_id); $file->store(); $arResult = array('VALUE' => $value); return $arResult; }
/** * Upload file from string using mime-type. * * @param string $content * @param string $mime_type * @return Uploadcare_File */ public function fromContent($content, $mime_type) { $tmpfile = tempnam(sys_get_temp_dir(), 'ucr'); $temp = fopen($tmpfile, 'w'); fwrite($temp, $content); fclose($temp); $data = array('UPLOADCARE_PUB_KEY' => $this->api->getPublicKey(), 'file' => sprintf('@%s;type=%s', $tmpfile, $mime_type)); $ch = $this->__initRequest('base'); $this->__setRequestType($ch); $this->__setData($ch, $data); $this->__setHeaders($ch); $data = $this->__runRequest($ch); $file_id = $data->file; return new Uploadcare_File($file_id, $this->api); }
/** * Delete file * * @return array */ public function delete() { return $this->api->__preparedRequest(API_TYPE_FILE, REQUEST_TYPE_DELETE, array('file_id' => $this->file_id)); }
/** * Returns <script> sections to include Uploadcare widget * * @param string $version Uploadcare version * @return string */ public function getScriptTag($version = null) { $result = sprintf('<script>UPLOADCARE_PUBLIC_KEY = "%s";</script>', $this->api->getPublicKey()); $result .= sprintf('<script async="async" src="%s"></script>', $this->getScriptSrc($version)); return $result; }
/** * Let's check the file operations and check for correct urls */ public function testFile() { $api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY); $file = $api->getFile('4bd3a897-f489-4b9f-b643-961b1c9f657e'); $this->assertEquals(get_class($file), 'Uploadcare_File'); $this->assertEquals($file->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/'); $this->assertEquals($file->resize(400, 400)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/resize/400x400/'); $this->assertEquals($file->resize(400, false)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/resize/400x/'); $this->assertEquals($file->resize(false, 400)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/resize/x400/'); $this->assertEquals($file->crop(400, 400)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/crop/400x400/'); $this->assertEquals($file->crop(400, 400, true)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/crop/400x400/center/'); $this->assertEquals($file->crop(400, 400, true, 'ff0000')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/crop/400x400/center/ff0000/'); $this->assertEquals($file->crop(400, 400, false, 'ff0000')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/crop/400x400/ff0000/'); $this->assertEquals($file->scaleCrop(400, 400)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/scale_crop/400x400/'); $this->assertEquals($file->scaleCrop(400, 400, true)->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/scale_crop/400x400/center/'); $this->assertEquals($file->effect('flip')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/flip/'); $this->assertEquals($file->effect('grayscale')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/grayscale/'); $this->assertEquals($file->effect('invert')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/invert/'); $this->assertEquals($file->effect('mirror')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/mirror/'); $this->assertEquals($file->effect('flip')->effect('mirror')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/flip/-/effect/mirror/'); $this->assertEquals($file->effect('mirror')->effect('flip')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/effect/mirror/-/effect/flip/'); $this->assertEquals($file->resize(400, 400)->scaleCrop(200, 200, true)->effect('mirror')->getUrl(), 'https://ucarecdn.com/4bd3a897-f489-4b9f-b643-961b1c9f657e/-/resize/400x400/-/scale_crop/200x200/center/-/effect/mirror/'); }
<?php // This is just some config with public and secret keys for UC. require_once 'config.php'; // requesting lib for PHP 5.2 require_once '../uploadcare/lib/5.2/Uploadcare.php'; // using namespace // create object istance for Api. $api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY); /** * Let's start with widgets. * You can get widget url by using this: * */ print $api->widget->getScriptSrc() . "\n"; /** * You can just use method below to get all the code to insert widget */ print $api->widget->getScriptTag() . "\n"; /** * Ok, lets do some requests. This is request to index (http://api.uploadcare.com). * This will return an stdClass with information about urls you can request. */ $data = $api->request('GET', '/'); /** * Ok, now lets get file list. * This request will return stdClass with all files uploaded and some information about files. * Each files has: * - size * - upload_date * - last_keep_claim * - on_s3
<? require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/tools/uploadcare/uploadcare-php/uploadcare/lib/5.2/Uploadcare.php"); require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php"); $public_key = COption::GetOptionString("uploadcare", "publickey"); $secret_key = COption::GetOptionString("uploadcare", "secretkey"); $uploadcare_api = new Uploadcare_Api($public_key, $secret_key); $file_id = $_GET['file_id']; $file = $uploadcare_api->getFile($file_id); $file->store(); print 'OK';
<?php error_reporting(E_ERROR); include dirname(__FILE__) . '/config.php'; include dirname(__FILE__) . '/uploadcare-php/uploadcare/lib/5.2/Uploadcare.php'; $public_key = UC_PUBLIC_KEY; $secret_key = UC_SECRET_KEY; $api = new Uploadcare_Api($public_key, $secret_key); $editor_name = $_REQUEST['editor_name']; //POST $file = null; $scale_crop_default_width = 800; $scale_crop_default_height = 634; if ($_POST['save']) { $file_id = $_POST['file_id']; $file = $api->getFile($file_id); $file->scaleCrop($scale_crop_default_width, $scale_crop_default_height); $file->op('stretch/off'); $file->store(); } if ($_GET['file_id']) { $file_id = $_GET['file_id']; $file = $api->getFile($file_id); $file->scaleCrop($scale_crop_default_width, $scale_crop_default_height); $file->op('stretch/off'); $file->store(); } $is_insert = false; $is_preview = false; if ($_POST['insert'] or $_POST['_preview']) { $file_id = $_POST['file_id'];