PHP code example of nubs / hiatus

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

    

nubs / hiatus example snippets



// Get the directory listing of the directory given by the user.
// NOTE: This is probably not a good idea to let users run arbitrary directory
// listings.
list($exitStatus, $stdout, $stderr) = \Hiatus\exec('ls -l', [$_POST['dir']]);

if ($exitStatus !== 0) {
    throw new Exception('Command failed.');
}

echo $stdout;


// Download the url given by the user, but fail if it takes more than 10
// seconds.
// NOTE: This is probably not a good idea to let users download arbitrary urls.
list($exitStatus, $stdout, $stderr) = \Hiatus\exec(
    'curl',
    [$_POST['url']],
    10
);

if ($exitStatus !== 0) {
    throw new Exception('Command failed.');
}

echo $stdout;


try {
    list($stdout, $stderr) = \Hiatus\execX('ls /foo');
} catch (Exception $e) {
    echo "Error occurred: {$e->getMessage()}\n";
    exit(1);
}

echo $stdout;


list($exitStatus, $stdout, $stderr) = \Hiatus\exec(
    'wc -c',
    [],
    null,
    'stdin test'
);

if ((int)$stdout !== 10) {
    echo "Well, this is awkward.\n";
}