Git Product home page Git Product logo

iconic0 / files-sdk-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from files-com/files-sdk-php

0.0 0.0 0.0 1.57 MB

Files.com Official PHP SDK. Files.com is Cloud Storage, Cloud Gateway, and MFT, All In One. Our built-in storage is fast, affordable, and available in 7 Worldwide Regions. Access Any File on Any Cloud via Files.com's PHP client, including Google, Amazon, Microsoft, Box, Dropbox, Amazon, Wasabi, Backblaze, Rackspace, and more.

Home Page: https://developers.files.com/

License: MIT License

Shell 0.27% PHP 99.73%

files-sdk-php's Introduction

Files.com PHP SDK

The Files.com PHP SDK provides convenient Files.com API access to applications written in PHP.

Installation

Install Composer. See https://packagist.org for more info.

If composer.phar is already available, skip this step.

curl -sS https://getcomposer.org/installer | php

Install the SDK

php composer.phar require files.com/files-php-sdk

Requirements

  • PHP 5.5+
  • php-curl extension

Usage

Import and initialize

    require 'vendor/autoload.php';

    // set your subdomain or custom domain
    \Files\Files::setBaseUrl('https://MY-SUBDOMAIN.files.com');

Authentication

There are multiple ways to authenticate to the API.

Global API Key

You can set an API key globally like this:

    \Files\Files::setApiKey('my-api-key');

Per-Request API Key

Or, you can pass an API key per-request, in the options array at the end of every method like this:

    $user = new \Files\Model\User($params, array('api_key' => 'my-api-key'));

User Session

Or, you can open a user session by calling \Files\Model\Session::create()

    $session = \Files\Model\Session::create(['username' => $username, 'password' => $password]);

Then use it globally for all subsequent API calls like this:

    \Files\Files::setSessionId($session->id);

Or, you can pass the session ID per-request, in the options array at the end of every method like this:

    $user = new \Files\Model\User($params, array('session_id' => $session->id));
Session example
    $session = \Files\Model\Session::create(['username' => $myUsername, 'password' => $myPassword]);
    \Files\Files::setSessionId($session->id);

    // do something
    \Files\Model\ApiKey::all(['user_id' => 0]);

    // clean up when done
    \Files\Model\Session::destroy();
    \Files\Files::setSessionId(null);

Setting Global Options

You can set the following global properties directly on the \Files\Files class:

  • \Files\Files::$logLevel - set to one of the following:
    • \Files\LogLevel::NONE
    • \Files\LogLevel::ERROR
    • \Files\LogLevel::WARN
    • \Files\LogLevel::INFO (default)
    • \Files\LogLevel::DEBUG
  • \Files\Files::$debugRequest - enable debug logging of API requests (default: false)
  • \Files\Files::$debugResponseHeaders - enable debug logging of API response headers (default: false)
  • \Files\Files::$connectTimeout - network connect timeout in seconds (default: 30.0)
  • \Files\Files::$readTimeout - network read timeout in seconds (default: 90.0)
  • \Files\Files::$maxNetworkRetries - max retries (default: 3)
  • \Files\Files::$minNetworkRetryDelay - minimum delay in seconds before retrying (default: 0.5)
  • \Files\Files::$maxNetworkRetryDelay - max delay in seconds before retrying (default: 1.5)
  • \Files\Files::$autoPaginate - auto-fetch all pages when results span multiple pages (default: true)

Static File Operations

List files in root folder

    $rootFiles = \Files\Model\Folder::listFor('/');

Uploading a file on disk

    \Files\Model\File::uploadFile($destinationFileName, $sourceFilePath);

Uploading raw file data

    \Files\Model\File::uploadData($destinationFileName, $fileData);

Download a file to stream

    \Files\Model\File::downloadToStream($remoteFilePath, $outputStream);

Download a file to disk

    // download entire file - with retries enabled
    \Files\Model\File::downloadToFile($remoteFilePath, $localFilePath);

    // partially download - just the first KB
    \Files\Model\File::partialDownloadToFile($remoteFilePath, $localFilePath, 0, 1023);

    // resume an incomplete download
    \Files\Model\File::resumeDownloadToFile($remoteFilePath, $localFilePath);

Getting a file record by path

    $foundFile = \Files\Model\File::find($remoteFilePath);

File Object Operations

Getting a file record by path

    $file = new \Files\Model\File();
    $file->get($remoteFilePath);
Updating metadata
    $file->update([
      'provided_mtime' => '2000-01-01T01:00:00Z',
      'priority_color' => 'red',
    ]);
Retrieving metadata
    $file->metadata([
      'with_previews' => true,
      'with_priority_color' => true,
    ]);

Comparing Case insensitive files and paths

For related documentation see Case Sensitivity Documentation.

    if(\Files\Util\PathUtil::same("Fïłèńämê.Txt", "filename.txt")) {
        echo "Paths are the same\n";
    }

Additional Documentation

Additional docs are available at https://developers.files.com

Getting Support

The Files.com team is happy to help with any SDK Integration challenges you may face.

Just email [email protected] and we'll get the process started.

files-sdk-php's People

Contributors

files-opensource-bot avatar bombino avatar iconic0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.