canaryphp/canaryphpfile

CanaryPHPFile Simple File Managing for php

v1.0 2019-12-24 06:52 UTC

This package is auto-updated.

Last update: 2024-04-24 17:19:47 UTC


README

Simple file manging for php

Classes Feature

  • Copy and move
  • read and write
  • Check file (Image|Audio|Video|Text)

How to Install

  • Availlable only with Composer :
  • Command :
composer require canaryphp/canaryphpfile
  • composer.json
{
    "require":{
        "canaryphp/canaryphpfile"
    }
}
  • After install read : CanaryPHPTools START.md: START.md

Examples

  1. Copy an File
require 'vendor/autoload.php';
$canary = new \CanaryPHPFile\Canary();
$canary->file(__DIR__.DS.'text.txt')->setNewName('new_name.txt')
                                    ->setNewDir(__DIR__.DS.'move_to')
                                    ->copy();
  1. Move an file
require 'vendor/autoload.php';
$canary = new \CanaryPHPFile\Canary();
$canary->file(__DIR__.DS.'text.txt')->setNewName('new_name.txt')
                                    ->setNewDir(__DIR__.DS.'move_to')
                                    ->move();
  1. get file info :
require 'vendor/autoload.php';
$canary = new \CanaryPHPFile\Canary();
$file = $canary->file(__DIR__.DS.'text.txt')->getInfo();
echo "<pre>";
var_dump($file);
echo "</pre>";
  1. Check file :
require 'vendor/autoload.php';
$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)
 */
  1. Put , get file content and delete file:
require 'vendor/autoload.php';
$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"
 *
 */
  1. Show Error :
require 'vendor/autoload.php';
$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 ." }
 *
 */

NOTICE

  • vendor folder and the vendor/autoload.php script are generated by composer ,there are not part from CanaryPHPFile