PHP code example of amplie-solucoes / ezfile

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

    

amplie-solucoes / ezfile example snippets


//Validate if a Directory or File exists
EzFile::exists('your_path');

//Using 'force' paramn to validate outsite main path
EzFile::exists('your_path', true);

/*
====== [ Function Return ] ===== 
EXISTS: true
NOT EXISTS: false
*/

//Create a Directory or File
EzFile::create('your_path');

//Create a Directory or File replacing special chars and set all to lowercase
EzFile::create('your_path', true);

//Using 'force' paramn to create outsite main path
EzFile::create('your_path', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Write a file replacing the content (the function will create the file if not exist)
EzFile::write('your_file_path', 'any_content_you_want');

//using 'replaceContent' as FALSE, to append the content at the end of file.
EzFile::write('your_file_path', 'any_content_you_want', false);

//Using 'force' paramn to write in a file outsite main path
EzFile::write('your_file_path', 'any_content_you_want', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Read the file that you want
EzFile::read('your_file_path');

//Using 'force' paramn to read a file outsite main path
EzFile::read('your_file_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: *The File Content*
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Rename a Directory or File
EzFile::rename('current_path', 'renamed_path');

//Rename a Directory or File replacing special chars and set all to lowercase
EzFile::rename('current_path', 'renamed_path', true);

//Using 'force' paramn to rename outsite main path
EzFile::rename('current_path', 'renamed_path', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Move a Directory or File
EzFile::move('current_path', 'move_path');

//Using 'force' paramn to move outsite main path
EzFile::move('current_path', 'move_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Copy a Directory (and all contents inside) or File
EzFile::copy('current_path', 'copy_path');

//Using 'force' paramn to copy outsite main path
EzFile::copy('current_path', 'copy_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Permission code set in a Directory or File
EzFile::changePermissions('your_path', 0777);
EzFile::changePermissions('your_path', 0666);
EzFile::changePermissions('your_path', 0700);
//... and other codes that you need

//Using 'force' paramn to change permissions outsite main path
EzFile::changePermissions('your_path', 0777, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Info of the Directory or File
EzFile::pathInfo('your_path');

//Using 'force' paramn to get pathinfo outsite main path
EzFile::pathInfo('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: [array_with_all_informations_that_you_need]
ERROR: ['error' => true, 'message' => 'error_message']
*/

//List a Directory
EzFile::list('your_path');

//Using 'force' paramn to list outsite main path
EzFile::list('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: [array_with_all_informations_that_you_need]
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Zip a Directory with all contents inside
EzFile::zip('your_folder_path', 'zip_path');

//Using 'force' paramn to zip outsite main path
EzFile::zip('your_folder_path', 'zip_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Unzip a file with all contents inside (ONLY ZIP FILES)
EzFile::unzip('your_zip_file_path', 'unzip_path');

//Using 'force' paramn to unzip outsite main path (ONLY ZIP FILES)
EzFile::unzip('your_zip_file_path', 'unzip_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Delete a Directory (and all contents inside) or File
EzFile::delete('your_path');

//Using 'force' paramn to delete outsite main path
EzFile::delete('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Upload a Directory (and all contents inside) or File(s)
EzFile::upload('upload_path', $_FILES);

//Uploading and renaming (the lib will interate automatically as new_name_1... new_name_2....)
EzFile::upload('upload_path', $_FILES, 'new_name');

//Uploading accept only files with
EzFile::upload('upload_path', $_FILES, false, ['txt', 'png', 'json', /* ... */]);

//Using 'force' paramn to Upload outsite main path
EzFile::upload('upload_path', $_FILES, false, [], true);

/*
====== [ Function Return ] ===== 
SUCCESS: ['success' => [], 'fail' => [], 'denied' => []]
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Download a Directory (and all contents inside) or File
EzFile::download('your_path');

//Using 'force' paramn to download outsite main path
EzFile::download('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: The user will receive the download item
ERROR: ['error' => true, 'message' => 'error_message']
*/

// Get size unit constants
EzFile::UNIT_BYTES;      //Return (string): "B"
EzFile::UNIT_KILOBYTES;  //Return (string): "KB"
EzFile::UNIT_MEGABYTES;  //Return (string): "MB"
EzFile::UNIT_GIGABYTES;  //Return (string): "GB"
EzFile::UNIT_TERABYTES;  //Return (string): "TB"
EzFile::UNIT_PETABYTES;  //Return (string): "PB"
EzFile::UNIT_EXABYTES;   //Return (string): "EB"
EzFile::UNIT_ZETTABYTES; //Return (string): "ZB"
EzFile::UNIT_YOTTABYTES; //Return (string): "YB"

// Format the value for human reading

//Formatting bytes Value
EzFile::sizeUnitFormatter(100); //Return (string): 100 B

//Formatting by setting computational unit
EzFile::sizeUnitFormatter(5, EzFile::UNIT_GIGABYTES);   //Return (string): 5 GB
EzFile::sizeUnitFormatter(500, EzFile::UNIT_GIGABYTES); //Return (string): 500 GB
EzFile::sizeUnitFormatter(1, EzFile::UNIT_TERABYTES);   //Return (string): 1 TB

//Formatting by setting computational unit with data in byte number
EzFile::sizeUnitFormatter(1, EzFile::UNIT_TERABYTES, true); //Return (string): 1099511627776 B

/*
====== [ Function Return ] ===== 
SUCCESS: Return a string value
ERROR: ['error' => true, 'message' => 'error_message']
*/

//Import the lib
use AmplieSolucoes\EzFile\EzFile;

//Example Creating a file/Directory
$ezFile = EzFile::create('your_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

//Example renaming a file/Directory
$ezFile = EzFile::rename('current_path', 'renamed_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

//Example getting the pathinfo from file/Directory
$ezFile = EzFile::pathInfo('your_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked, get all data from the array $ezFile
}

//Example uploading file(s)/Directory(ies)
$ezFile = EzFile::upload('upload_path', $your_files_in_array);
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked, get all data from the array $ezFile
}

//Example writing file(s)
$ezFile = EzFile::write('file_path_name_with_extension', 'any_content');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

['error' => true, 'message' => 'error_message']