PHP code example of radzserg / php-box-view
1. Go to this page and download the library: Download radzserg/php-box-view library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
radzserg / php-box-view example snippets
$exampleApiKey = 'YOUR_API_KEY';
php examples/examples.php
$boxView = new Box\View\Client('YOUR_API_KEY');
// without options
$handle = fopen($filename, 'r');
$document = $boxView->uploadFile($handle);
// with options
$handle = fopen($filename, 'r');
$document = $boxView->uploadFile($handle, [
'name' => 'Test File',
'thumbnails' => ['100x100', '200x200'],
'nonSvg' => true,
]);
object(Box\View\Document)#54 (5) {
["createdAt":"Box\View\Document":private]=>
string(25) "2015-03-11T07:48:52+00:00"
["id":"Box\View\Document":private]=>
string(32) "0971e7674469406dba53254fcbb11d05"
["name":"Box\View\Document":private]=>
string(11) "Sample File"
["status":"Box\View\Document":private]=>
string(6) "queued"
}
// without options
$document = $boxView->uploadUrl($url);
// with options
$document = $boxView->uploadUrl($url, [
'name' => 'Test File',
'thumbnails' => ['100x100', '200x200'],
'nonSvg' => true,
]);
object(Box\View\Document)#54 (5) {
["createdAt":"Box\View\Document":private]=>
string(25) "2015-03-11T07:48:52+00:00"
["id":"Box\View\Document":private]=>
string(32) "0971e7674469406dba53254fcbb11d05"
["name":"Box\View\Document":private]=>
string(11) "Sample File"
["status":"Box\View\Document":private]=>
string(6) "queued"
}
$document = $boxView->getDocument($documentId);
object(Box\View\Document)#54 (5) {
["createdAt":"Box\View\Document":private]=>
string(25) "2015-03-11T07:48:52+00:00"
["id":"Box\View\Document":private]=>
string(32) "0971e7674469406dba53254fcbb11d05"
["name":"Box\View\Document":private]=>
string(11) "Sample File"
["status":"Box\View\Document":private]=>
string(6) "queued"
}
// without options
$documents = $boxView->findDocuments();
// with options
$start = date('c', strtotime('-2 weeks'));
$end = date('c', strtotime('-1 week'));
$documents = $boxView->findDocuments([
'limit' => 10,
'createdAfter' => $start,
'createdBefore' => $end,
]);
array(2) {
[0]=>
object(Box\View\Document)#31 (5) {
["createdAt":"Box\View\Document":private]=>
string(25) "2015-03-11T07:50:41+00:00"
["id":"Box\View\Document":private]=>
string(32) "f2f9be2249e2490da3b0a040d5eaae58"
["name":"Box\View\Document":private]=>
string(14) "Sample File #2"
["status":"Box\View\Document":private]=>
string(10) "processing"
}
[1]=>
object(Box\View\Document)#55 (5) {
["createdAt":"Box\View\Document":private]=>
string(25) "2015-03-11T07:50:40+00:00"
["id":"Box\View\Document":private]=>
string(32) "966f747cb77b4f1b805cc594c9fdd30c"
["name":"Box\View\Document":private]=>
string(11) "Sample File"
["status":"Box\View\Document":private]=>
string(4) "done"
}
}
$contents = $document->download();
$filename = __DIR__ . '/files/new-file.doc';
$handle = fopen($filename, 'w');
fwrite($handle, $contents);
fclose($handle);
$thumbnailContents = $document->thumbnail(100, 100);
$filename = __DIR__ . '/files/new-thumbnail.png';
$handle = fopen($filename, 'w');
fwrite($handle, $thumbnailContents);
fclose($handle);
$updated = $document->update(['name' => 'Updated Name']);
if ($updated) {
// do something
} else {
// do something else
}
bool(true)
$deleted = $document->delete();
if ($deleted) {
// do something
} else {
// do something else
}
bool(true)
// without options
$session = $document->createSession();
// with options
$session = $document->createSession([
'expiresAt' => date('c', strtotime('+10 min')),
'isDownloadable' => true,
'isTextSelectable' => false,
]);
object(Box\View\Session)#41 (5) {
["document":"Box\View\Session":private]=>
object(Box\View\Document)#27 (5) {
...
}
["id":"Box\View\Session":private]=>
string(32) "d1b8c35a69da43fbb2e978e99589114a"
["expiresAt":"Box\View\Session":private]=>
string(25) "2015-03-11T08:53:23+00:00"
["urls":"Box\View\Session":private]=>
array(3) {
["assets"]=>
string(76) "https://view-api.box.com/1/sessions/d1b8c35a69da43fbb2e978e99589114a/assets/"
["realtime"]=>
string(61) "https://view-api.box.com/sse/d1b8c35a69da43fbb2e978e99589114a"
["view"]=>
string(73) "https://view-api.box.com/1/sessions/d1b8c35a69da43fbb2e978e99589114a/view"
}
}
$deleted = $session->delete();
if ($deleted) {
// do something
} else {
// do something else
}
bool(true)
bash
curl -sS https://getcomposer.org/installer | php