PHP code example of padosoft / io
1. Go to this page and download the library: Download padosoft/io 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/ */
padosoft / io example snippets
if(FileHelper::checkDirExistOrCreate('public/upload', '0755')){
echo 'dir already exists or now created!';
}else{
echo 'OOPS! dir not exists and unable to create it!';
}
//get all files in public/upload/
$arrFiles = FileHelper::findFiles('public/upload/*');
var_dump($arrFiles);
//get all jpeg in public/upload/
$arrFiles = FileHelper::findFiles('public/upload/*.jpg');
var_dump($arrFiles);
//check if the path ends with slash
if(DirHelper::endsWithSlash('public/upload')){
echo 'add a final slash...';
$path = DirHelper::addFinalSlash('public/upload');
echo $path;
}else{
echo 'path already finish with slash.';
}
//get all directories in public/upload/
$arrFolders = DirHelper::findDirs('public/upload/*');
var_dump($arrFolders);
//truncate log to last 2000 bytes without truncate line
echo 'before:'.PHP_EOL;
echo file_get_contents('log.csv');
if(LogHelper::ftruncatestart('log.csv', 2000)){
echo 'after:'.PHP_EOL;
echo file_get_contents('log.csv');
}