PHP Classes

File: src/examples/cmdline_example.php

Recommend this page to a friend!
  Classes of Martin Latter  >  PHP Detect File Type  >  src/examples/cmdline_example.php  >  Download  
File: src/examples/cmdline_example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Detect File Type
Identify files via MIME type and file signatures
Author: By
Last change:
Date: 2 years ago
Size: 1,253 bytes
 

Contents

Class file image Download
#!/usr/bin/env php
<?php

/**
    * Command-line example usage of FileIdentifier class.
    *
    * Usage:
    * php <thisfilename> <filename>
    * ./<thisfilename> <filename>
    *
    * @author Martin Latter
    * @copyright Martin Latter 15/06/2016
    * @version 0.17
    * @license GNU GPL v3.0
    * @link https://github.com/Tinram/File-Identifier.git
*/

declare(strict_types=1);

###################################################
require('../FileIdentifier.php');
require(
'../FileSignatures.php');
###################################################

use Tinram\FileIdentifier\FileIdentifier;

if ( ! isset(
$_SERVER['argv'][1]))
{
   
$sUsage =
       
PHP_EOL . ' ' .
       
basename(__FILE__, '.php') .
       
PHP_EOL . PHP_EOL .
       
"\tusage: php " . basename(__FILE__) . ' <filename>' .
       
PHP_EOL . PHP_EOL;

    die(
$sUsage);
}

$sFile = $_SERVER['argv'][1];

if ( !
file_exists($sFile))
{
    die(
'\'' . $sFile . '\' does not exist in this directory!' . PHP_EOL);
}
else
{
   
$oFileCheck = new FileIdentifier($sFile);
   
$aResult = $oFileCheck->getResult();

    echo
$sFile . ':' . PHP_EOL;
    echo
$aResult['mimeinfo'] . PHP_EOL;
    echo
$aResult['fileinfo'] . PHP_EOL;
}

For more information send a message to info at phpclasses dot org.