PHP code example of files.com / files-php-sdk

1. Go to this page and download the library: Download files.com/files-php-sdk 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/ */

    

files.com / files-php-sdk example snippets


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

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

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

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

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

    $user = new \Files\Model\User($params, array('session_id' => $session->id));

    $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);

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

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

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

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

    // 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);

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

    $file = new \Files\Model\File();
    $file->get($remoteFilePath);

    $file->update([
      'provided_mtime' => '2000-01-01T01:00:00Z',
      'priority_color' => 'red',
    ]);

    $file->metadata([
      'with_previews' => true,
      'with_priority_color' => true,
    ]);

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