getFile() public method

Get object of File class by id
public getFile ( string $uuid_or_url ) : File
$uuid_or_url string Uploadcare file UUID or CDN URL
return File
Ejemplo n.º 1
0
 public function testFileConstructor()
 {
     $f = $this->api->getFile('3c99da1d-ef05-4d79-81d8-d4f208d98beb');
     $this->assertEquals('3c99da1d-ef05-4d79-81d8-d4f208d98beb', $f->getUuid());
     $f = $this->api->getFile('https://ucarecdn.com/3c99da1d-ef05-4d79-81d8-d4f208d98beb/-/preview/100x100/-/effect/grayscale/bill.jpg');
     $this->assertEquals('3c99da1d-ef05-4d79-81d8-d4f208d98beb', $f->getUuid());
     $this->assertEquals('preview/100x100/-/effect/grayscale/', $f->default_effects);
     $this->assertEquals('bill.jpg', $f->filename);
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 4
0
    echo $file->getUuid() . "\n";
}
/**
 * Listing only first 4 file ids (if you want to use pagination)
 */
$page = 1;
$per_page = 4;
for ($i = ($page - 1) * $per_page; $i < min(count($files), $page * $per_page); $i++) {
    echo $file->getUuid() . "\n";
}
/**
 * If you have a file_id (for example, it's saved in your database) you can create object for file easily.
 * Just user request below
*/
$file_id = '5255b9dd-f790-425e-9fa9-8b49d4e64643';
$file = $api->getFile($file_id);
/**
 * Ok, using object of \Uploadcare\File class we can get url for the file
*/
echo $file->getUrl() . "\n";
/**
 * Or even get an image tag
 */
echo $file->getImgTag('image.jpg', array('alt' => 'Somealt')) . "\n";
/**
 * Now let's do some crop.
 */
$width = 400;
$height = 400;
$is_center = true;
$fill_color = 'ff0000';
Ejemplo n.º 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>
Ejemplo n.º 6
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/');
 }