Example #1
0
 public function testGroupConstructor()
 {
     $g = $this->api->getGroup('cd334b26-c641-4393-bcce-b5041546430d~11');
     $this->assertEquals('cd334b26-c641-4393-bcce-b5041546430d~11', $g->getUuid());
     $this->assertEquals(11, $g->getFilesQty());
     $g = $this->api->getGroup('https://ucarecdn.com/cd334b26-c641-4393-bcce-b5041546430d~11/');
     $this->assertEquals('cd334b26-c641-4393-bcce-b5041546430d~11', $g->getUuid());
     $this->assertEquals(11, $g->getFilesQty());
 }
Example #2
0
 public function test_FileGroupHasCroppingInfo()
 {
     $f1 = $this->api->uploader->fromContent('1', 'text/plain');
     $f2 = $this->api->getFile($f1->getUrl() . '-/crop/2x2/');
     $g = $this->api->uploader->createGroup(array($f2));
     foreach ($g->getFiles() as $f) {
         $this->assertEquals("https://ucarecdn.com/" . $f1->getUuid() . '/-/crop/2x2/', $f->getUrl());
     }
 }
Example #3
0
 public function testFileConstructor()
 {
     $api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
     $f = $api->getFile('3c99da1d-ef05-4d79-81d8-d4f208d98beb');
     $this->assertEquals('3c99da1d-ef05-4d79-81d8-d4f208d98beb', $f->getFileId());
     $f = $api->getFile('http://www.ucarecdn.com/3c99da1d-ef05-4d79-81d8-d4f208d98beb/-/preview/100x100/-/effect/grayscale/bill.jpg');
     $this->assertEquals('3c99da1d-ef05-4d79-81d8-d4f208d98beb', $f->getFileId());
     $this->assertEquals('preview/100x100/-/effect/grayscale/', $f->default_effects);
     $this->assertEquals('bill.jpg', $f->filename);
 }
Example #4
0
<?php

/**
 * Examples
 */
// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting autoloader that got uploadcare in there
require_once 'vendor/autoload.php';
// using api
use Uploadcare\Api;
// create object instance for Api.
$api = new 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:
Example #5
0
<?php

require_once 'config.php';
require_once '../uploadcare/lib/5.3-5.4/Uploadcare.php';
use Uploadcare;
$file_id = $_POST['qs-file'];
$uc_handler = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$file = $uc_handler->getFile($file_id);
try {
    $file->store();
} catch (Exception $e) {
    echo $e->getMessage() . "<br />";
    echo nl2br($e->getTraceAsString());
    die;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta encoding='utf-8'>
<title>Uploadcare</title>
<link
	href="// ucarecdn.com/assets/application-68fbe95c430b7646b16aef33e1ad2824.css"
	media="screen" rel="stylesheet" type="text/css" />
<link
	href="https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|PT+Sans+Caption&amp;subset=latin,cyrillic"
	media="screen" rel="stylesheet" type="text/css" />
<script
	src="// ucarecdn.com/assets/application-241564109602bb3ae298c344abff83a7.js"
	type="text/javascript"></script>
</head>
Example #6
0
<?php

/**
 * Examples
 */
// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting autoloader that got uploadcare in there
require_once 'vendor/autoload.php';
// using api
use Uploadcare\Api;
// create object istance for Api.
$api = new 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:
Example #7
0
<?php

// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting autoloader that got uploadcare in there
require_once 'vendor/autoload.php';
// using api
use Uploadcare\Api;
// create object instance for Api.
$api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
// get all files iterator
// using filter: only files uploaded earlier than 14 days ago
$files = $api->getFileList(array('to' => new \DateTime('-14 days')));
/** @var \Uploadcare\File $file */
foreach ($files as $file) {
    $originalFilename = $file->data['original_filename'];
    $file->delete();
    echo "{$originalFilename} (" . $file . ") removed<br>";
}
 public function __construct($public, $private)
 {
     parent::__construct($public, $private);
 }
Example #9
0
<?php

/**
 * This example shows how to download all files from Uploadcare storage
 * to your local disk
 */
// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting autoloader that got uploadcare in there
require_once 'vendor/autoload.php';
// using api
use Uploadcare\Api;
// create object instance for Api.
$api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
// get all files iterator
$files = $api->getFileList();
// folder to store files in
$folder = 'download';
// creating a folder for downloaded files
if (!file_exists($folder)) {
    mkdir($folder);
}
chmod($folder, 0775);
/** @var \Uploadcare\File $file */
foreach ($files as $file) {
    $originalFilename = $file->data['original_filename'];
    // if you see an error on this line like this: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
    // then you should enable openssl extension in php
    // more info here: http://ru.stackoverflow.com/questions/222688/denwer-รจ-file-get-contents
    file_put_contents($folder . '/' . $originalFilename, fopen($file, 'r'));
    echo "downloaded {$originalFilename} (" . filesize($folder . '/' . $originalFilename) . " bytes)<br>";
Example #10
0
 /**
  * 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/');
 }