Exemple #1
0
 public function ShowFiles($folder_id)
 {
     $box_items = parent::get_folder_items($folder_id);
     $items = array();
     if (isset($box_items['entries'])) {
         if (is_array($box_items['entries'])) {
             foreach ($box_items['entries'] as $entries) {
                 if ($this->Get_type($entries['type']) == 0) {
                     array_push($items, array("name" => $entries['name'], "id" => $entries['id'], "type" => $entries['type'], "link" => null, "url" => null, "size" => null, "download_count" => null));
                 } else {
                     if ($this->Get_type($entries['type']) == 1) {
                         $file_item = parent::get_file_details($entries['id']);
                         $shared = $file_item['shared_link'];
                         $url = null;
                         $link = null;
                         $download = null;
                         if (count($shared) != 0 || $shared != null) {
                             $url = $shared['url'];
                             $link = $shared['download_url'];
                             $download = $shared['download_count'];
                         }
                         array_push($items, array("name" => $file_item['name'], "id" => $file_item['id'], "type" => $file_item['type'], "link" => $link, "url" => $url, "size" => round($file_item['size'] / 1024 / 1024, 2) . " Mb", "download_count" => $download));
                     }
                 }
             }
         }
     }
     return $items;
 }
Exemple #2
0
<?php

include 'src/BoxAPI.class.php';
$client_id = 'CLIENT ID';
$client_secret = 'CLIENT SECRET';
$redirect_uri = 'REDIRECT URL';
$box = new Box_API($client_id, $client_secret, $redirect_uri);
if (!$box->load_token()) {
    if (isset($_GET['code'])) {
        $token = $box->get_token($_GET['code'], true);
        if ($box->write_token($token, 'file')) {
            $box->load_token();
        }
    } else {
        $box->get_code();
    }
}
// User details
$box->get_user();
// Get folder details
$box->get_folder_details('FOLDER ID');
// Get folder items list
$box->get_folder_items('FOLDER ID');
// All folders in particular folder
$box->get_folders('FOLDER ID');
// All Files in a particular folder
$box->get_files('FOLDER ID');
// All Web links in a particular folder
$box->get_links('FOLDER ID');
// Get folder collaborators list
$box->get_folder_collaborators('FOLDER ID');
 function __construct()
 {
     include 'library/BoxAPI.class.php';
     $client_id = 'CLIENT ID';
     $client_secret = 'CLIENT SECRET';
     $redirect_uri = 'REDIRECT URL';
     $box = new Box_API($client_id, $client_secret, $redirect_uri);
     if (!$box->load_token()) {
         if (isset($_GET['code'])) {
             $token = $box->get_token($_GET['code'], true);
             if ($box->write_token($token, 'file')) {
                 $box->load_token();
             }
         } else {
             $box->get_code();
         }
     }
     // User details
     $box->get_user();
     // Get folder details
     $box->get_folder_details('FOLDER ID');
     // Get folder items list
     $box->get_folder_items('FOLDER ID');
     // All folders in particular folder
     $box->get_folders('FOLDER ID');
     // All Files in a particular folder
     $box->get_files('FOLDER ID');
     // All Web links in a particular folder
     $box->get_links('FOLDER ID');
     // Get folder collaborators list
     $box->get_folder_collaborators('FOLDER ID');
     // Create folder
     $box->create_folder('FOLDER NAME', 'PARENT FOLDER ID');
     // Update folder details
     $details['name'] = 'NEW FOLDER NAME';
     $box->update_folder('FOLDER ID', $details);
     // Share folder
     $params['shared_link']['access'] = 'ACCESS TYPE';
     //open|company|collaborators
     print_r($box->share_folder('FOLDER ID', $params));
     // Delete folder
     $opts['recursive'] = 'true';
     $box->delete_folder('FOLDER ID', $opts);
     // Get file details
     $box->get_file_details('FILE ID');
     // Upload file
     $box->put_file('RELATIVE FILE URL', '0');
     // Update file details
     $details['name'] = 'NEW FILE NAME';
     $details['description'] = 'NEW DESCRIPTION FOR THE FILE';
     $box->update_file('FILE ID', $details);
     // Share file
     $params['shared_link']['access'] = 'ACCESS TYPE';
     //open|company|collaborators
     print_r($box->share_file('File ID', $params));
     // Delete file
     $box->delete_file('FILE ID');
     if (isset($box->error)) {
         echo $box->error . "\n";
     }
 }
<?php

if (!isset($_GET['id'])) {
    exit;
}
if (!isset($_GET['secret'])) {
    exit;
}
if (!isset($_GET['redirect'])) {
    exit;
}
if (!isset($_GET['code'])) {
    exit;
}
include 'BoxAPI.class.php';
$box = new Box_API($_GET['id'], $_GET['secret'], $_GET['redirect']);
if ($box) {
    echo $box->get_token($_GET['code'], true);
}
Exemple #5
0
 public function connect()
 {
     $failed = false;
     try {
         $box = new Box_API($this->auth1, $this->auth2, $this->auth3);
         // BOX TOKENS EXPIRE AUTOMATICALLY
         //   ACCESS TOKENS = 1 hr
         //   REFRESH TOKENS = 60 days
         $loaded_token = $box->load_token($this->auth5);
         if (!$loaded_token) {
             $failed = true;
         } else {
             if ($loaded_token !== true) {
                 // THE TOKEN WAS AUTOMATICALLY UPDATED, NOW WE NEED TO STORE IT SOMEWHERE
             }
         }
         if (!$failed) {
             $this->store = $box;
             //$m=$this->store->getMetadata( $this->container_url($this->bucket) );
             /*
                             if ( !isset($m['path']) )
                             {
                                 $res = $this->store->createFolder( $this->container_url($this->bucket) );
                                 if (!$res)
                                 {
                                     $failed=true;
                                 }
                             }*/
         }
     } catch (Exception $e) {
         $failed = true;
     }
     return $this->connectcheck($failed);
 }