getFileList() public method

This class provides iteration over all uploaded files. You can specify: - $options['from'] - a DateTime object or string from which objects will be iterated; - $options['to'] - a DateTime object or string to which objects will be iterated; - $options['limit'] - a total number of objects to be iterated; If not specified, all available objects are iterated; - $options['request_limit'] - a number of objects to be downloaded per request. - $options['stored'] - True to include only stored files, False to exclude, Null is default, will not exclude anything; - $options['removed'] - True to include only removed files, False to exclude, Null will not exclude anything. The default is False.
public getFileList ( array $options = [] ) : FileIterator
$options array
return FileIterator
Esempio n. 1
0
 /**
  * Test that getFilesList method returns array
  * and each item of array is an object of Uploadcare\File class
  */
 public function testFileList()
 {
     $api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
     $files = $api->getFileList();
     $this->assertTrue(is_array($files));
     $this->assertEquals(20, count($files));
     $files = $api->getFileList(1, 2);
     $this->assertTrue(is_array($files));
     $this->assertEquals(2, count($files));
     foreach ($files as $file) {
         $this->assertTrue(get_class($file) == 'Uploadcare\\File');
     }
 }
Esempio n. 2
0
 /**
  * Test that getFilesList method returns array
  * and each item of array is an object of Uploadcare\File class
  */
 public function testFileList()
 {
     $files = $this->api->getFileList(array('limit' => 20));
     $this->assertFalse(is_array($files));
     $this->assertTrue(is_object($files));
     $this->assertTrue($files instanceof \Iterator);
     $this->assertTrue($files instanceof Uploadcare\FileIterator);
     $this->assertEquals(20, count($files));
     $files = $this->api->getFileList(array('limit' => 2));
     $this->assertFalse(is_array($files));
     $this->assertTrue(is_object($files));
     $this->assertTrue($files instanceof \Iterator);
     $this->assertTrue($files instanceof Uploadcare\FileIterator);
     $this->assertEquals(2, count($files));
     foreach ($files as $file) {
         $this->assertTrue(get_class($file) == 'Uploadcare\\File');
     }
 }
Esempio n. 3
0
 *  - original_filename
 *  - removed
 *  - mime_type
 *  - original_file_url
 *
*/
$files_raw = $api->request('GET', '/files/');
/**
 *  Previous request is just some raw request and it will return raw data from json.
 *  There's a better way to handle all the files by using method below.
 *  It will return an array of \Uploadcare\File objects to work with.
 *
 *  This objects don't provide all the data like in previous request, but provides ways to display the file
 *  and to use methods such as resize, crop, etc
*/
$files = $api->getFileList();
echo "We have " . count($files) . " file(s)\n";
/**
 * Listing all file ids
 */
/** @var Uploadcare\File $file */
foreach ($files as $file) {
    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";
Esempio n. 4
0
 *  - original_filename
 *  - removed
 *  - mime_type
 *  - original_file_url
 *
*/
$files_raw = $api->request('GET', '/files/');
/**
 *  Previous request is just some raw request and it will return raw data from json.
 *  There's a better way to handle all the files by using method below.
 *  It will return an array of \Uploadcare\File objects to work with.
 *
 *  This objects don't provide all the data like in previous request, but provides ways to display the file
 *  and to use methods such as resize, crop, etc
*/
$files = $api->getFileList();
/**
 * getFileList called without any params will return just an array of first 20 files objects (first page).
 *
 * But you can supply a page you want to see:
*/
$page = 2;
$files = $api->getFileList($page);
/**
 * You can get some information about pagination.
 *
 * You will get an array with params:
 * - page: current page
 * - next: uri to request next page
 * - per_page: number of files per page
 * - pages: number of pages
Esempio n. 5
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>";
}