PHP code example of canaryphp / canaryphpfile

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

    

canaryphp / canaryphpfile example snippets



$canary = new \CanaryPHPFile\Canary();
$canary->file(__DIR__.DS.'text.txt')->setNewName('new_name.txt')
                                    ->setNewDir(__DIR__.DS.'move_to')
                                    ->copy();


$canary = new \CanaryPHPFile\Canary();
$canary->file(__DIR__.DS.'text.txt')->setNewName('new_name.txt')
                                    ->setNewDir(__DIR__.DS.'move_to')
                                    ->move();


$canary = new \CanaryPHPFile\Canary();
$file = $canary->file(__DIR__.DS.'text.txt')->getInfo();
echo "<pre>";
var_dump($file);
echo "</pre>";


$canary = new \CanaryPHPFile\Canary();
$file = $canary->file(__DIR__.DS.'text.txt');
//Check image
$image = $file->checkImage();
//Check Text
$text =  $file->checkText();
//Check Audio
$audio = $file->checkAudio();
//Check Video
$video = $file->checkVideo();
echo "<br>";
var_dump("File is Image :",$image);
echo "<br>";
echo var_dump("File is text :",$text);
echo "<br>";
echo var_dump("File is audio :",$audio);
echo "<br>";
echo var_dump("File is video :",$video);
echo "<br>";
/**
 * output :
 * string(15) "File is Image :"bool(false)
 * string(14) "File is text :"bool(true)
 * string(15) "File is audio :"bool(false)
 *string(15) "File is video :"bool(false)
 */


$canary = new \CanaryPHPFile\Canary();
$file = $canary->file(__DIR__.DS.'text.txt');
//Put new file content
$file->put('This new Content');
//get file content
$content = $file->get();
//show content
var_dump($content);
//Delete file
$file->delete();
/**
 * // output :
 *
 * string(16) "This new Content"
 *
 */


$canary = new \CanaryPHPFile\Canary();
$file = $canary->file(__DIR__.DS.'text.txt');
$file->setNewName('new_name.txt')
                                ->setNewDir(__DIR__.DS.'doesnt/exist/folder')
                                ->move();
var_dump($file->FILE_ERRORS());
/**
 * //output
 *
 * array(1) { [0]=> string(95) "FileError(E:\xampp\htdocs\canary_file\doesnt/exist/folder) : The folder does not exist ." }
 *
 */