PHP code example of genilto / sbackup

1. Go to this page and download the library: Download genilto/sbackup 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/ */

    

genilto / sbackup example snippets


<!DOCTYPE  html>
<html  lang="pt-br">
<head>
<meta  charset="utf-8"/>
<title>SBackup tests!</title>
</head>
<body>
 <div  style="padding: 50px; text-align: center; max-width: 500px; margin: auto;">
  <h1  style="padding: 20px;">SBackup <small>Tests</small></h1>
  <div>
   <a href="auth.php">1 - Go to Authentication page</a>
  </div>
  <div>
   <a href="upload.php">2 - Go to Upload page</a>
  </div>
 </div>
</body>
</html>


 \genilto\sbackup\SBackup;
use  \genilto\sbackup\adapters\SBackupDropbox;
use  \genilto\sbackup\store\FileDataStore;
use  \genilto\sbackup\logger\SBLogger;

use  \Analog\Analog;
use  \Analog\Logger;

// Defines the default timezone
Analog::$timezone =  'America/Sao_Paulo';
date_default_timezone_set(Analog::$timezone);

if (!function_exists('createDefaultLogger')) {

 /**
 * Creates the default logger using Analog as Logger class
 * Any other PSR-3 Logger could be used
 *
 * @return  SBLogger
 */
 function  createDefaultSBackupLogger () {
  // Creates the Default Logger
  $logger =  new  Logger();
  // Define where to save the logs
  $currentDate =  date("Y-m-d");
  $logger->handler (__DIR__  .  "/$currentDate-sbackup.log");
  // Return a SBLogger instance
  return  new  SBLogger($logger, 3); // 3 - Full Logging
 }
}

/**
* Define the IENT_SECRET);

// The main SBackup class that will the available to be used
$SBackup = new SBackup($SBUploader, $SBLogger);


  
// In production, it is very important to create some kind of
// Authorization, blocking users that do not have access to authenticate with
// the cloud service, as dropbox.

// If anyone reachs this page, they could authenticate their 
// own account and then receive all your uploaded files!!

// Include the backup.config.php file so we have the $SBackup object available



* Return the error description of the uploaded file
 * 
 * @param string $path
 * 
 * @return string|false The function returns the error description or false on failure.
 */
function getUploadErrorDescription ($uploadErrorCode) {
    $phpFileUploadErrors = array(
        0 => 'There is no error, the file uploaded with success',
        1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
        2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
        3 => 'The uploaded file was only partially uploaded',
        4 => 'No file was uploaded',
        6 => 'Missing a temporary folder',
        7 => 'Failed to write file to disk.',
        8 => 'A PHP extension stopped the file upload.',
    );

    if (isset($phpFileUploadErrors[$uploadErrorCode])) {
        return $phpFileUploadErrors[$uploadErrorCode];
    }
    return false;
}