PHP code example of shone / scanner

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

    

shone / scanner example snippets



use Shone\Scanner\Scanner;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;

$scanner = new Scanner();

// Set your API key
$scanner->setKey([API KEY]);

// Enable SSL certificate checking
$scanner->setCertCheck(true);

// Set the label of the job you want to submit or search for
$scanner->setLabel("Website Label");

// You can build a list of files anyway you want like:
// $files = array('/path/to/file1', '/path/to/file2');
// I find the easiest way is like this:
$filesystem = new Filesystem(new Local("path/to/scan"));
$files = $scanner->buildFileList($filesystem);

// Build our packet to send to the API
$packet = $scanner->buildJobPacket($filesystem, $files);

// Send the packet to the framework
$result = $scanner->submitJob($packet);

if ($result['Status'] != 'Success') {
    // Something went wrong
    throw new \Exception($result['Detail']);
} else {
    $hash = $result['Hash'];
}

// Wait a little while and attempt to get the result (might take a few seconds to process)
$max_retry = 5;
$attempt = 1;
while ($attempt < $max_retry)
{
    sleep(2);
    $job = $scanner->getJob($hash);
    if (empty($job['status']) || $job['status'] != 'In progress')
    {
        break;
    }
    $attempt++;
}

// The job result:
print_r($job);