new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use stdClass;
|
||||
|
||||
class Content
|
||||
{
|
||||
/**
|
||||
* Read File
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function read(string $file) : string
|
||||
{
|
||||
return file_get_contents(Info::rpath($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Data
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $data
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function find(string $file, string $data) : stdClass
|
||||
{
|
||||
$contents = self::read($file);
|
||||
$index = strpos($contents, $data);
|
||||
|
||||
return (object)
|
||||
[
|
||||
'index' => $index,
|
||||
'contents' => $contents
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Data
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function write(string $file, string $data) : int
|
||||
{
|
||||
return file_put_contents(Info::rpath($file), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append Data
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function append(string $file, string $data) : int
|
||||
{
|
||||
return file_put_contents(Info::rpath($file), $data, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
|
||||
class Converter
|
||||
{
|
||||
/**
|
||||
* Sets delimiter.
|
||||
*
|
||||
* @var string $delimiter = ''
|
||||
*/
|
||||
protected static $delimiter = ';';
|
||||
|
||||
/**
|
||||
* Sets delimiter.
|
||||
*
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
*/
|
||||
public static function delimiter(string $delimiter)
|
||||
{
|
||||
self::$delimiter = $delimiter;
|
||||
|
||||
return new self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to XLS
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $file = 'excel.xls'
|
||||
* @param bool $useBoom = false
|
||||
*/
|
||||
public static function arrayToXLS(array $data, string $file = 'excel', bool $useBom = false, string $extension = '.xls')
|
||||
{
|
||||
$file = Base::suffix($file, $extension);
|
||||
|
||||
header("Content-Disposition: attachment; filename=\"$file\"");
|
||||
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
|
||||
$output = fopen("php://output", 'w');
|
||||
|
||||
if( $useBom === true )
|
||||
{
|
||||
echo "\xEF\xBB\xBF";
|
||||
}
|
||||
|
||||
foreach( $data as $column )
|
||||
{
|
||||
echo implode($extension === '.csv' ? self::$delimiter : '\t', $column) . EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to CSV
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $file = 'excel.csv'
|
||||
* @param bool $useBoom = false
|
||||
*/
|
||||
public static function arrayToCSV(array $data, string $file = 'excel', bool $useBom = false)
|
||||
{
|
||||
self::arrayToXLS($data, $file, $useBom, '.csv');
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV to Array
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function CSVToArray(string $file) : array
|
||||
{
|
||||
$file = Base::suffix($file, '.csv');
|
||||
|
||||
if( ! is_file($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$row = 1;
|
||||
$rows = [];
|
||||
|
||||
if( ( $resource = fopen($file, "r") ) !== false )
|
||||
{
|
||||
while( ($data = fgetcsv($resource, 1000, ",")) !== false )
|
||||
{
|
||||
$num = count($data);
|
||||
|
||||
$row++;
|
||||
|
||||
for( $c = 0; $c < $num; $c++ )
|
||||
{
|
||||
$rows[] = explode(self::$delimiter, $data[$c]);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($resource);
|
||||
}
|
||||
|
||||
self::$delimiter = ';';
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Document
|
||||
{
|
||||
/**
|
||||
* Magic Call
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $parameters
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if( substr($this->target, -1) === '/' )
|
||||
{
|
||||
$type = 'Folder';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'File';
|
||||
}
|
||||
|
||||
$this->apply = $type::$method($this->target, ...$parameters);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target File
|
||||
*
|
||||
* @param string $target
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function target(string $target) : Document
|
||||
{
|
||||
$this->target = $target;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply changes
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
return $this->apply ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Datatype;
|
||||
|
||||
class Download
|
||||
{
|
||||
/**
|
||||
* Download
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
public static function start(string $file)
|
||||
{
|
||||
if( ! Info::available($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException($file);
|
||||
}
|
||||
|
||||
self::readFileContent($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected read file content
|
||||
*/
|
||||
protected static function readFileContent($file)
|
||||
{
|
||||
header("Content-type: application/x-download");
|
||||
header("Content-Disposition: attachment; filename=" . Datatype::divide($file, '/', -1));
|
||||
|
||||
readfile($file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Filesystem\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class FileNotFoundException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` file was not found!',
|
||||
'tr' => '`%` dosyasi bulunamadi!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Filesystem\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class FolderNotFoundException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` directory was not found!',
|
||||
'tr' => '`%` dizini bulunamadi!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Filesystem\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class UndefinedFunctionException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => 'Call to undefined function `%`!',
|
||||
'tr' => '%` fonksiyonu tanımlı değil!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem;
|
||||
|
||||
class Extension
|
||||
{
|
||||
/**
|
||||
* Get Extension
|
||||
*
|
||||
* @param string $file
|
||||
* @param bool $dot = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get(string $file, bool $dot = false) : string
|
||||
{
|
||||
return Filesystem::getExtension($file, $dot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Extension
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function remove(string $file) : string
|
||||
{
|
||||
return Filesystem::removeExtension($file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Controller\Factory;
|
||||
|
||||
class File extends Factory
|
||||
{
|
||||
const factory =
|
||||
[
|
||||
'methods' =>
|
||||
[
|
||||
'copy' => 'Forge::copy',
|
||||
'settings' => 'Transfer::settings',
|
||||
'upload' => 'Transfer::upload',
|
||||
'download' => 'Transfer::download',
|
||||
'exists' => 'Info::exists',
|
||||
'originpath' => 'Info::originpath',
|
||||
'relativepath' => 'Info::relativepath',
|
||||
'absolutepath' => 'Info::absolutepath',
|
||||
'available' => 'Info::available',
|
||||
'executable' => 'Info::executable',
|
||||
'writable' => 'Info::writable',
|
||||
'writeable' => 'Info::writeable',
|
||||
'readable' => 'Info::readable',
|
||||
'uploaded' => 'Info::uploaded',
|
||||
'access' => 'Info::access:this',
|
||||
'rpath' => 'Info::rpath',
|
||||
'info' => 'Info::get',
|
||||
'pathinfo' => 'Info::pathInfo',
|
||||
'size' => 'Info::size',
|
||||
'createdate' => 'Info::createDate',
|
||||
'changedate' => 'Info::changeDate',
|
||||
'owner' => 'Info::owner',
|
||||
'group' => 'Info::group',
|
||||
'rowcount' => 'Info::rowCount',
|
||||
'required' => 'Info::required',
|
||||
'read' => 'Content::read',
|
||||
'contents' => 'Content::read',
|
||||
'find' => 'Content::find',
|
||||
'write' => 'Content::write',
|
||||
'append' => 'Content::append',
|
||||
'generate' => 'Forge::generate',
|
||||
'create' => 'Forge::create',
|
||||
'replace' => 'Forge::replace',
|
||||
'reglace' => 'Forge::reglace',
|
||||
'delete' => 'Forge::delete',
|
||||
'readzip' => 'Info::readZip',
|
||||
'zipextract' => 'Forge::zipExtract',
|
||||
'createzip' => 'Forge::createZip',
|
||||
'rename' => 'Forge::rename',
|
||||
'cleancache' => 'Forge::cleanCache',
|
||||
'truncate' => 'Forge::truncate',
|
||||
'permission' => 'Forge::permission',
|
||||
'require' => 'Loader::require',
|
||||
'requireonce' => 'Loader::requireOnce',
|
||||
'include' => 'Loader::include',
|
||||
'includeonce' => 'Loader::includeOnce',
|
||||
'extension' => 'Extension::get',
|
||||
'removeextension' => 'Extension::remove'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem;
|
||||
use ZN\Filesystem\Exception\FolderNotFoundException;
|
||||
|
||||
class FileList
|
||||
{
|
||||
/**
|
||||
* Used to retrieve a list of files and directories within a directory.
|
||||
* If it is desired to list files with a certain extension between the files to be listed,
|
||||
* the file extension for the second parameter can be used.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $extension = NULL
|
||||
* @param bool $pathType = false
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function files(string $path, $extension = NULL, bool $pathType = false) : array
|
||||
{
|
||||
$path = Info::rpath($path);
|
||||
|
||||
if( ! is_dir($path) )
|
||||
{
|
||||
throw new FolderNotFoundException(NULL, $path);
|
||||
}
|
||||
|
||||
return Filesystem::getFiles($path, $extension, $pathType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to retrieve a list of all subdirectories and files belonging to a directory.
|
||||
* You can set the second parameter to true
|
||||
* if you want to list the files that are also in the nested indexes.
|
||||
*
|
||||
* @param string $pattern = '*'
|
||||
* @param bool $allFiles = false
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function allFiles(string $pattern = '*', bool $allFiles = false) : array
|
||||
{
|
||||
return Filesystem::getRecursiveFiles($pattern, $allFiles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* Enabled when the language file can not be accessed.
|
||||
*/
|
||||
class FilesystemDefaultLanguage
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Upload
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The language of the Upload library.
|
||||
|
|
||||
*/
|
||||
|
||||
public $en =
|
||||
[
|
||||
'upload:extensionError' => 'Invalid file extension!',
|
||||
'upload:mimeError' => 'Invalid mime type!',
|
||||
'upload:unknownError' => 'Unknown error or file is too large!',
|
||||
'upload:0' => 'The file was uploaded successfully.',
|
||||
'upload:1' => 'Maximum file size exceeded your php.ini file!',
|
||||
'upload:2' => 'Form max_file_size directive file size limit has been exceeded!',
|
||||
'upload:3' => 'File partially uploaded!',
|
||||
'upload:4' => 'Upload file does not exist!',
|
||||
'upload:6' => 'files to install a temporary directory not found!',
|
||||
'upload:7' => 'Failed to write file to disk!',
|
||||
'upload:8' => 'File upload does not support the extension!',
|
||||
'upload:9' => 'File installation path is not valid!',
|
||||
'upload:10' => 'Determine the maximum file size has been exceeded!'
|
||||
];
|
||||
|
||||
public $tr =
|
||||
[
|
||||
'upload:extensionError' => 'Geçersiz dosya uzantısı!',
|
||||
'upload:mimeError' => 'Geçersiz mime türü!',
|
||||
'upload:unknownError' => 'Bilinmeyen hata veya çok büyük boyutlu dosya!',
|
||||
'upload:0' => 'Dosya başarı ile yüklendi.',
|
||||
'upload:1' => 'Php.ini dosyasındaki maximum dosya boyutu aşıldı!',
|
||||
'upload:2' => 'Formdaki max_file_size direktifindeki dosya boyutu limiti aşıldı!',
|
||||
'upload:3' => 'Dosya kısmen yüklendi!',
|
||||
'upload:4' => 'Yüklenecek dosya yok!',
|
||||
'upload:6' => 'Dosyaların geçici olarak yükleneceği dizin bulunamadı!',
|
||||
'upload:7' => 'Dosya diske yazılamadı!',
|
||||
'upload:8' => 'Dosya yükleme uzantı desteği yok!',
|
||||
'upload:9' => 'Dosya yükleme yolu geçerli değil!',
|
||||
'upload:10' => 'Belirlenen maksimum dosya boyutu aşıldı!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Controller\Factory;
|
||||
|
||||
class Folder extends Factory
|
||||
{
|
||||
const factory =
|
||||
[
|
||||
'methods' =>
|
||||
[
|
||||
'exists' => 'Info::existsFolder',
|
||||
'fileinfo' => 'Info::fileInfo',
|
||||
'info' => 'Info::get',
|
||||
'basepath' => 'Info::basePath',
|
||||
'disk' => 'Info::disk',
|
||||
'totalspace' => 'Info::totalSpace',
|
||||
'freespace' => 'Info::freeSpace',
|
||||
'disk' => 'Info::disk',
|
||||
'create' => 'Forge::createFolder',
|
||||
'rename' => 'Forge::rename',
|
||||
'deleteempty' => 'Forge::deleteEmptyFolder',
|
||||
'delete' => 'Forge::deleteFolder',
|
||||
'copy' => 'Forge::copy',
|
||||
'change' => 'Forge::changeFolder',
|
||||
'permission' => 'Forge::permission',
|
||||
'files' => 'FileList::files',
|
||||
'allfiles' => 'FileList::allFiles'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZipArchive;
|
||||
use ZN\Base;
|
||||
use ZN\Regex;
|
||||
use ZN\Filesystem;
|
||||
|
||||
class Forge
|
||||
{
|
||||
/**
|
||||
* Creates a file.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(string $name) : bool
|
||||
{
|
||||
return Filesystem::createFile(Info::rpath($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs data modification on the file.
|
||||
*
|
||||
* @param string $file
|
||||
* @param mixed $data
|
||||
* @param mixed $replace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function replace(string $file, $data, $replace) : string
|
||||
{
|
||||
$file = Info::rpath($file);
|
||||
|
||||
if( ! is_file($file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Filesystem::replaceData($file, $data, $replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs data modification on the file with ZN regex.
|
||||
*
|
||||
* @param string $file
|
||||
* @param mixed $pattern
|
||||
* @param mixed $replace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reglace(string $file, $pattern, $replace) : string
|
||||
{
|
||||
$file = Info::rpath($file);
|
||||
|
||||
if( ! is_file($file))
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
$replaceContents = (new Regex)->replace($pattern, $replace, $contents);
|
||||
|
||||
if( $contents !== $replaceContents )
|
||||
{
|
||||
file_put_contents($file, $replaceContents);
|
||||
}
|
||||
|
||||
return $replaceContents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the file.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete(string $name) : bool
|
||||
{
|
||||
$name = Info::rpath($name);
|
||||
|
||||
if( ! is_file($name))
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return unlink($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a zip file to the specified location.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function zipExtract(string $source, ?string $target = NULL) : bool
|
||||
{
|
||||
$source = Info::rpath($source);
|
||||
$target = Info::rpath($target);
|
||||
|
||||
$source = Base::suffix($source, '.zip');
|
||||
|
||||
if( ! file_exists($source) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $source);
|
||||
}
|
||||
|
||||
if( empty($target) )
|
||||
{
|
||||
$target = Extension::remove($source);
|
||||
}
|
||||
|
||||
$zip = new ZipArchive;
|
||||
|
||||
if( $zip->open($source) === true )
|
||||
{
|
||||
$zip->extractTo($target);
|
||||
$zip->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a zip file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function createZip(string $path, array $data) : bool
|
||||
{
|
||||
$opath = $path;
|
||||
$path = Info::rpath($path);
|
||||
$zip = new ZipArchive;
|
||||
$zipPath = Base::suffix($path, ".zip");
|
||||
|
||||
if( file_exists($zipPath) )
|
||||
{
|
||||
unlink($zipPath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! is_dir($pathDirName = Info::pathInfo($path, 'dirname')) )
|
||||
{
|
||||
mkdir($pathDirName);
|
||||
}
|
||||
|
||||
$zip->open($zipPath, ZipArchive::CREATE);
|
||||
|
||||
$status = '';
|
||||
|
||||
if( ! empty($data) ) foreach( $data as $key => $val )
|
||||
{
|
||||
if( is_numeric($key) )
|
||||
{
|
||||
$file = $val;
|
||||
$fileName = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $key;
|
||||
$fileName = $val;
|
||||
}
|
||||
|
||||
if( is_dir($file) )
|
||||
{
|
||||
$allFiles = FileList::allFiles($file, true);
|
||||
|
||||
foreach( $allFiles as $f )
|
||||
{
|
||||
$status = $zip->addFile($f, Base::removePrefix($f, Base::suffix($opath)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = $zip->addFile($file, $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
return $zip->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the name of a file.
|
||||
*
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function rename(string $oldName, string $newName) : bool
|
||||
{
|
||||
$oldName = Info::rpath($oldName);
|
||||
|
||||
if( ! file_exists($oldName) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $oldName);
|
||||
}
|
||||
|
||||
return rename($oldName, $newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears file status cache
|
||||
*
|
||||
* @param string $fileName = NULL
|
||||
* @param bool $real = false
|
||||
*/
|
||||
public static function cleanCache(?string $fileName = NULL, bool $real = false)
|
||||
{
|
||||
$fileName = Info::rpath($fileName);
|
||||
|
||||
if( ! file_exists($fileName) )
|
||||
{
|
||||
clearstatcache($real);
|
||||
}
|
||||
else
|
||||
{
|
||||
clearstatcache($real, $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates a file to a given length
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $limit = 0
|
||||
* @param string $mode = 'r+'
|
||||
*/
|
||||
public static function truncate(string $file, int $limit = 0, string $mode = 'r+')
|
||||
{
|
||||
$file = Info::rpath($file);
|
||||
|
||||
if( ! is_file($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$fileOpen = fopen($file, $mode);
|
||||
$fileWrite = ftruncate($fileOpen, $limit);
|
||||
|
||||
fclose($fileOpen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes file mode.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $permission = 0755
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function permission(string $name, int $permission = 0755) : bool
|
||||
{
|
||||
$name = Info::rpath($name);
|
||||
|
||||
if( ! file_exists($name) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $name);
|
||||
}
|
||||
|
||||
return chmod($name, $permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index.
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $permission = 0755
|
||||
* @param bool $recursive = true
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function createFolder(string $file, int $permission = 0755, bool $recursive = true) : bool
|
||||
{
|
||||
return Filesystem::createFolder(Info::rpath($file), $permission, $recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to delete an empty directory.
|
||||
*
|
||||
* @param string $folder
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteEmptyFolder(string $folder) : bool
|
||||
{
|
||||
return Filesystem::deleteEmptyFolder(Info::rpath($folder));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to delete a directory along with its contents.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteFolder(string $name) : bool
|
||||
{
|
||||
return Filesystem::deleteFolder(Info::rpath($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to copy a directory to another specified location.
|
||||
* This includes other subdirectories and files of the directory to be copied.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function copy(string $source, string $target) : bool
|
||||
{
|
||||
return Filesystem::copy(Info::rpath($source), Info::rpath($target));
|
||||
}
|
||||
|
||||
/**
|
||||
* It is used to change the active working directory of PHP.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function changeFolder(string $name) : bool
|
||||
{
|
||||
$name = Info::rpath($name);
|
||||
|
||||
if( ! is_dir($name) )
|
||||
{
|
||||
throw new Exception\FolderNotFoundException(NULL, $name);
|
||||
}
|
||||
|
||||
return chdir($name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
use stdClass;
|
||||
use ZN\Config;
|
||||
use ZipArchive;
|
||||
|
||||
class Info
|
||||
{
|
||||
/**
|
||||
* Access Status
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $access = NULL;
|
||||
|
||||
/**
|
||||
* Keeps is methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $methods =
|
||||
[
|
||||
'executable' => 'is_executable',
|
||||
'writable' => 'is_writable',
|
||||
'writeable' => 'is_writeable',
|
||||
'readable' => 'is_readable',
|
||||
'uploaded' => 'is_uploaded_file'
|
||||
];
|
||||
|
||||
/**
|
||||
* Magic Call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return self::_is($method, ...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Path Info
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $info = 'basename'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pathInfo(string $file, string $info = 'basename') : string
|
||||
{
|
||||
$pathInfo = pathinfo($file);
|
||||
|
||||
return $pathInfo[$info] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required files
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function required() : array
|
||||
{
|
||||
return get_required_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets access status
|
||||
*
|
||||
* @param bool $realPath = true
|
||||
* @param bool $parentDirectoryAccess = false
|
||||
*
|
||||
* @return Info
|
||||
*/
|
||||
public function access($realPath = true, $parentDirectoryAccess = false) : Info
|
||||
{
|
||||
self::$access['realPath'] = $realPath;
|
||||
self::$access['parentDirectoryAccess'] = $parentDirectoryAccess;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Real Path
|
||||
*
|
||||
* @param string $file = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function rpath(?string $file = NULL) : string
|
||||
{
|
||||
$file = $file ?? '';
|
||||
|
||||
$config = Config::get('Filesystem', 'file', self::$access);
|
||||
|
||||
self::$access = NULL;
|
||||
|
||||
if( $config['parentDirectoryAccess'] === false )
|
||||
{
|
||||
$file = str_replace('../', '', $file);
|
||||
}
|
||||
|
||||
if( $config['realPath'] === true )
|
||||
{
|
||||
$file = Base::prefix(self::originpath($file), self::originpath(REAL_BASE_DIR));
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* File Exists
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists(string $file) : bool
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Zip
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function readZip(string $file) : array
|
||||
{
|
||||
$file = self::rpath(Base::suffix($file, '.zip'));
|
||||
|
||||
$archive = new ZipArchive($file);
|
||||
|
||||
$archive->open($file);
|
||||
|
||||
$returnFiles = [];
|
||||
|
||||
for( $i = 0; $i < $archive->numFiles; $i++ )
|
||||
{
|
||||
$stat = $archive->statIndex($i);
|
||||
|
||||
$returnFiles[] = $stat['name'];
|
||||
}
|
||||
|
||||
return $returnFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Original Path
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function originpath(string $string) : string
|
||||
{
|
||||
return str_replace(['/', '\\'], DS, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Realtive Path
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function relativepath(string $string) : string
|
||||
{
|
||||
return str_replace(REAL_BASE_DIR, '', self::originpath($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Available
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function available(string $file) : bool
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( file_exists($file) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file info
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function get(string $file) : stdClass
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
return (object)
|
||||
[
|
||||
'basename' => self::pathInfo($file, 'basename'),
|
||||
'size' => filesize($file),
|
||||
'date' => filemtime($file),
|
||||
'readable' => is_readable($file),
|
||||
'writable' => is_writable($file),
|
||||
'executable' => is_executable($file),
|
||||
'permission' => self::fileperm($file)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file size
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $type = 'b'
|
||||
* @param int $decimal = 2
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function size(string $file, string $type = 'b', int $decimal = 2) : Float
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$size = 0;
|
||||
$fileSize = filesize($file);
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
$size += $fileSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
$folderFiles = FileList::files($file);
|
||||
|
||||
if( $folderFiles )
|
||||
{
|
||||
foreach( $folderFiles as $val )
|
||||
{
|
||||
$size += self::size($file."/".$val);
|
||||
}
|
||||
|
||||
$size += $fileSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
$size += $fileSize; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
# BYTES
|
||||
if( $type === "b" )
|
||||
{
|
||||
return $size;
|
||||
}
|
||||
# KILO BYTES
|
||||
if( $type === "kb" )
|
||||
{
|
||||
return round($size / 1024, $decimal);
|
||||
}
|
||||
# MEGA BYTES
|
||||
if( $type === "mb" )
|
||||
{
|
||||
return round($size / (1024 * 1024), $decimal);
|
||||
}
|
||||
# GIGA BYTES
|
||||
if( $type === "gb" )
|
||||
{
|
||||
return round($size / (1024 * 1024 * 1024), $decimal);
|
||||
}
|
||||
|
||||
return $size; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Get create date
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $type = 'd.m.Y G:i:s'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function createDate(string $file, string $type = 'd.m.Y G:i:s') : string
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$date = filectime($file);
|
||||
|
||||
return date($type, $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get change date
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $type = 'd.m.Y G:i:s'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function changeDate(string $file, string $type = 'd.m.Y G:i:s') : string
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$date = filemtime($file);
|
||||
|
||||
return date($type, $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file owner
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return array|int
|
||||
*/
|
||||
public static function owner(string $file)
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$owner = fileowner($file);
|
||||
|
||||
if( function_exists('posix_getpwuid') )
|
||||
{
|
||||
return posix_getpwuid($owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $owner; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file group
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return array|int
|
||||
*/
|
||||
public static function group(string $file)
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
$group = filegroup($file);
|
||||
|
||||
if( function_exists('posix_getgrgid') )
|
||||
{
|
||||
return posix_getgrgid($group);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $group; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of file row
|
||||
*
|
||||
* @return string $file = '/'
|
||||
* @param bool $recursive = true
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function rowCount(string $file = '/', bool $recursive = true) : int
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
return count( file($file) );
|
||||
}
|
||||
# Is dir
|
||||
else
|
||||
{
|
||||
$files = FileList::allFiles($file, $recursive);
|
||||
|
||||
$rowCount = 0;
|
||||
|
||||
foreach( $files as $f )
|
||||
{
|
||||
if( is_file($f) )
|
||||
{
|
||||
$rowCount += count( file($f) );
|
||||
}
|
||||
}
|
||||
|
||||
return $rowCount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get base path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function basePath() : string
|
||||
{
|
||||
return getcwd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists Folder
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function existsFolder(string $file) : bool
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
if( is_dir($file) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get various information about a file or directory.
|
||||
*
|
||||
* @param string $dir
|
||||
* @param string $extension = NULL
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fileInfo(string $dir, ?string $extension = NULL) : array
|
||||
{
|
||||
$dir = self::rpath($dir);
|
||||
|
||||
if( is_dir($dir) )
|
||||
{
|
||||
$files = FileList::files($dir, $extension);
|
||||
|
||||
$dir = Base::suffix($dir);
|
||||
|
||||
$filesInfo = [];
|
||||
|
||||
foreach( $files as $file )
|
||||
{
|
||||
$path = $dir . $file;
|
||||
|
||||
$filesInfo[$file]['basename'] = self::pathInfo($path, 'basename');
|
||||
$filesInfo[$file]['size'] = filesize($path);
|
||||
$filesInfo[$file]['date'] = filemtime($path);
|
||||
$filesInfo[$file]['readable'] = is_readable($path);
|
||||
$filesInfo[$file]['writable'] = is_writable($path);
|
||||
$filesInfo[$file]['executable'] = is_executable($path);
|
||||
$filesInfo[$file]['permission'] = self::fileperm($path);
|
||||
}
|
||||
|
||||
return $filesInfo;
|
||||
}
|
||||
elseif( is_file($dir) )
|
||||
{
|
||||
return (array) self::get($dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception\FolderNotFoundException(NULL, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get free disk space
|
||||
*
|
||||
* @param string $dir
|
||||
* @param string $type = 'free'
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function disk(string $dir, string $type = 'free') : Float
|
||||
{
|
||||
$dir = self::rpath($dir);
|
||||
|
||||
if( ! is_dir($dir) )
|
||||
{
|
||||
throw new Exception\FolderNotFoundException(NULL, $dir);
|
||||
}
|
||||
|
||||
if( $type === 'free' )
|
||||
{
|
||||
return disk_free_space($dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
return disk_total_space($dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total disk space
|
||||
*
|
||||
* @param string $dir
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function totalSpace(string $dir) : Float
|
||||
{
|
||||
return self::disk($dir, 'total');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get free disk space
|
||||
*
|
||||
* @param string $dir
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function freeSpace(string $dir) : Float
|
||||
{
|
||||
return self::disk($dir, 'free');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected IS
|
||||
*/
|
||||
protected static function _is($type, $file)
|
||||
{
|
||||
$file = self::rpath($file);
|
||||
|
||||
$validType = self::$methods[$type] ?? NULL;
|
||||
|
||||
if( ! function_exists($validType) || $validType === NULL )
|
||||
{
|
||||
throw new Exception\UndefinedFunctionException(NULL, get_called_class().'::'.$type.'()'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( $validType($file) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected file permission
|
||||
*/
|
||||
protected static function fileperm($file)
|
||||
{
|
||||
return substr(sprintf('%o', fileperms($file)), -4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Loader
|
||||
{
|
||||
/**
|
||||
* Require File
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $type = 'require'
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function require(string $file, string $type = 'require')
|
||||
{
|
||||
$file = Info::rpath($file);
|
||||
|
||||
if( ! is_file($file) )
|
||||
{
|
||||
throw new Exception\FileNotFoundException(NULL, $file);
|
||||
}
|
||||
|
||||
switch( $type )
|
||||
{
|
||||
case 'require' : return require $file;
|
||||
case 'require_once': return require_once $file;
|
||||
case 'include' : return include $file;
|
||||
case 'include_once': return include_once $file;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Require Once
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function requireOnce(string $file)
|
||||
{
|
||||
return self::require($file, 'require_once');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function include(string $file)
|
||||
{
|
||||
return self::require($file, 'include');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Once
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function includeOnce(string $file)
|
||||
{
|
||||
return self::require($file, 'include_once');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{[
|
||||
$uploadProgressFunction = 'uploadprogress' . md5(uniqid());
|
||||
$callable;
|
||||
]}
|
||||
<script>
|
||||
function {{ $uploadProgressFunction }}(callableUploadProgress)
|
||||
{
|
||||
var formdata = new FormData();
|
||||
var request = new XMLHttpRequest();
|
||||
var progress = callableUploadProgress;
|
||||
var files = $('{{ $source }}')[0].files;
|
||||
|
||||
for( index = 0; index < files.length; index++ )
|
||||
{
|
||||
formdata.append('uploads', files[index]);
|
||||
}
|
||||
|
||||
request.upload.addEventListener('progress', function(e)
|
||||
{
|
||||
if( e.loaded <= e.total )
|
||||
{
|
||||
var percent = Math.ceil(e.loaded / e.total * 100);
|
||||
|
||||
progress(percent, e.loaded, e.total);
|
||||
}
|
||||
});
|
||||
|
||||
request.open('post', '/echo/percent');
|
||||
request.send(formdata);
|
||||
}
|
||||
|
||||
@selector($selector)->click(function() use($uploadProgressFunction, $callable)
|
||||
{<
|
||||
{{ $uploadProgressFunction }}(function(percent, loaded, total)
|
||||
{
|
||||
{{ $callable() }}
|
||||
});
|
||||
>})
|
||||
</script>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem\Exception\FileNotFoundException;
|
||||
|
||||
class Transfer
|
||||
{
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @param array $set
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public static function settings(array $set = [])
|
||||
{
|
||||
return \Upload::settings($set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload
|
||||
*
|
||||
* @param string $file = 'upload'
|
||||
* @param string $rootDir = UPLOADS_DIR
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function upload(string $fileName = 'upload', string $rootDir = UPLOADS_DIR) : bool
|
||||
{
|
||||
return \Upload::start($fileName, $rootDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
public static function download(string $file)
|
||||
{
|
||||
Download::start($file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,626 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\IS;
|
||||
use ZN\Base;
|
||||
use ZN\Lang;
|
||||
use ZN\Inclusion;
|
||||
use ZN\Helpers\Mime;
|
||||
use ZN\Request\Method;
|
||||
use ZN\DataTypes\Arrays;
|
||||
use ZN\Helpers\Converter;
|
||||
use ZN\Cryptography\Encode;
|
||||
|
||||
class Upload implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Keeps settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $settings =
|
||||
[
|
||||
'encode' => 'md5',
|
||||
'encodeLength' => 8,
|
||||
'extensions' => [],
|
||||
'mimes' => [],
|
||||
'convertName' => true,
|
||||
'prefix' => NULL,
|
||||
'maxsize' => NULL
|
||||
];
|
||||
|
||||
/**
|
||||
* Keeps file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* Extension Control
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $extensionControl;
|
||||
|
||||
/**
|
||||
* Keeps errors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $errors;
|
||||
|
||||
/**
|
||||
* Keeps manuel errors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* Keeps manuel error
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $manuelError;
|
||||
|
||||
/**
|
||||
* Keeps encode name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $encodeName;
|
||||
|
||||
/**
|
||||
* Keeps file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Keeps upload directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $uploadDirectory = UPLOADS_DIR ?: 'upload/';
|
||||
|
||||
/**
|
||||
* Keeps lang
|
||||
*/
|
||||
protected $getLang;
|
||||
|
||||
/**
|
||||
* Magic Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->getLang = Lang::default('ZN\Filesystem\FilesystemDefaultLanguage')::select('Filesystem');
|
||||
}
|
||||
|
||||
/**
|
||||
* Uplaod progress
|
||||
*
|
||||
* @param string $selector
|
||||
* @param string $source
|
||||
* @param callable $callable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function progress(string $selector, string $source, callable $callable) : string
|
||||
{
|
||||
return Inclusion\View::use('upload-progress',
|
||||
[
|
||||
'selector' => $selector,
|
||||
'source' => $source,
|
||||
'callable' => $callable
|
||||
|
||||
], true, __DIR__ . '/Resources/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is file input name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFile(string $name) : bool
|
||||
{
|
||||
$file = Method::files($name);
|
||||
|
||||
if( is_array($file) )
|
||||
{
|
||||
return (bool) $file[0]; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return (bool) Method::files($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function settings(array $settings = []) : Upload
|
||||
{
|
||||
foreach( $settings as $key => $val )
|
||||
{
|
||||
$this->settings[$key] = $val;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extensions
|
||||
*
|
||||
* @param string ...$args
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function extensions(...$args) : Upload
|
||||
{
|
||||
if( ! empty($args ) )
|
||||
{
|
||||
$this->settings['extensions'] = implode('|', $args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets convert name
|
||||
*
|
||||
* @param string|bool $convert = true
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function convertName($convert = true) : Upload
|
||||
{
|
||||
$this->settings['convertName'] = $convert;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets mimes
|
||||
*
|
||||
* @param string ...$args
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function mimes(...$args) : Upload
|
||||
{
|
||||
if( ! empty($args ) )
|
||||
{
|
||||
$this->settings['mimes'] = implode('|', $args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines encode type
|
||||
*
|
||||
* @param string $hash = 'md5'
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function encode(string $hash = 'md5') : Upload
|
||||
{
|
||||
$this->settings['encode'] = $hash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets prefix
|
||||
*
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function prefix(string $prefix) : Upload
|
||||
{
|
||||
$this->settings['prefix'] = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maxsize
|
||||
*
|
||||
* @param string|int $maxsize = 0
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function maxsize($maxsize = 0) : Upload
|
||||
{
|
||||
$this->settings['maxsize'] = $maxsize;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets encode length
|
||||
*
|
||||
* @param int $encodeLength = 8
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function encodeLength(int $encodeLength = 8) : Upload
|
||||
{
|
||||
$this->settings['encodeLength'] = $encodeLength;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets target
|
||||
*
|
||||
* @param string $target
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function target(string $target) : Upload
|
||||
{
|
||||
$this->settings['target'] = $target;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets source
|
||||
*
|
||||
* @param string $source = 'upload'
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function source(string $source = 'upload') : Upload
|
||||
{
|
||||
$this->settings['source'] = $source;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start file upload
|
||||
*
|
||||
* @param string $fileName = 'upload'
|
||||
* @param string $rootDir = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function start(string $fileName = 'upload', ?string $rootDir = NULL) : bool
|
||||
{
|
||||
$fileName = $this->settings['source'] ?? $fileName;
|
||||
$rootDir = $this->settings['target'] ?? $rootDir ?? $this->uploadDirectory;
|
||||
|
||||
if( ! is_dir($rootDir) )
|
||||
{
|
||||
mkdir($rootDir);
|
||||
}
|
||||
|
||||
$extensions = $this->_separator('extensions');
|
||||
$mimes = $this->_separator('mimes');
|
||||
|
||||
$this->file = $fileName;
|
||||
$encryption = $this->settings['prefix'] ?? '';
|
||||
$name = $_FILES[$fileName]['name'] ?? NULL;
|
||||
$source = $_FILES[$fileName]['tmp_name'] ?? NULL;
|
||||
$root = Base::suffix($rootDir, '/');
|
||||
|
||||
if( is_array($name) )
|
||||
{
|
||||
for( $index = 0; $index < count($name); $index++ )
|
||||
{
|
||||
$status = $this->_upload($rootDir, $root, $source[$index], $name[$index], $extensions, $mimes, $encryption);
|
||||
|
||||
$this->error[] = $status === true ? 0 : $status;
|
||||
}
|
||||
|
||||
$return = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = $this->_upload($rootDir, $root, $source, $name, $extensions, $mimes, $encryption);
|
||||
|
||||
$this->error = $return === true ? 0 : $return;
|
||||
}
|
||||
|
||||
$this->_default();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets info
|
||||
*
|
||||
* @param string $info = NULL
|
||||
*
|
||||
* @return object|false
|
||||
*/
|
||||
public function info(?string $info = NULL)
|
||||
{
|
||||
if( ! empty($_FILES[$this->file]) )
|
||||
{
|
||||
$datas =
|
||||
[
|
||||
'name' => $_FILES[$this->file]['name'],
|
||||
'type' => $_FILES[$this->file]['type'],
|
||||
'size' => $_FILES[$this->file]['size'],
|
||||
'tmpName' => $_FILES[$this->file]['tmp_name'],
|
||||
'error' => $_FILES[$this->file]['error'],
|
||||
'path' => $this->path,
|
||||
'encodeName' => $this->encodeName
|
||||
];
|
||||
|
||||
$values = [];
|
||||
|
||||
if( ! is_array($_FILES[$this->file]['name']) ) foreach( $datas as $key => $val )
|
||||
{
|
||||
if( $key === 'error' )
|
||||
{
|
||||
$val = $val ?: $this->error;
|
||||
}
|
||||
|
||||
$values[$key] = $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $datas as $key => $val )
|
||||
{
|
||||
if( ! empty($datas[$key]) )
|
||||
{
|
||||
foreach( (array) $datas[$key] as $k => $v )
|
||||
{
|
||||
if( $key === 'error' )
|
||||
{
|
||||
$v = $v ?: $this->error[$k];
|
||||
}
|
||||
|
||||
$values[$key][] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( isset($values[$info]) )
|
||||
{
|
||||
return $values[$info];
|
||||
}
|
||||
|
||||
return (object) $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets error
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$errorNo = $_FILES[$this->file]['error'] ?? NULL;
|
||||
|
||||
if( $errorNo === NULL )
|
||||
{
|
||||
return $this->getLang['upload:unknownError']; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( is_array($errorNo) )
|
||||
{
|
||||
$errno = 0;
|
||||
|
||||
foreach( $errorNo as $no )
|
||||
{
|
||||
if( ! empty($no) )
|
||||
{
|
||||
$errno = $no; // @codeCoverageIgnore
|
||||
break; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
$errorNo = $errno;
|
||||
}
|
||||
|
||||
$lang = $this->getLang;
|
||||
|
||||
$this->errors =
|
||||
[
|
||||
'0' => "scc",
|
||||
'1' => $lang['upload:1'],
|
||||
'2' => $lang['upload:2'],
|
||||
'3' => $lang['upload:3'],
|
||||
'4' => $lang['upload:4'],
|
||||
'6' => $lang['upload:6'],
|
||||
'7' => $lang['upload:7'],
|
||||
'8' => $lang['upload:8'],
|
||||
'9' => $lang['upload:9'],
|
||||
'10' => $lang['upload:10']
|
||||
];
|
||||
|
||||
if( ! empty($this->manuelError) )
|
||||
{
|
||||
return $this->errors[$this->manuelError];
|
||||
}
|
||||
elseif( ! empty($this->extensionControl) )
|
||||
{
|
||||
return $this->extensionControl;
|
||||
}
|
||||
elseif( ! empty($this->errors[$errorNo]) )
|
||||
{
|
||||
if( $this->errors[$errorNo] === "scc" )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->errors[$errorNo]; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return $lang['upload:unknownError']; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
$uploadFiles = (array) $this->info()->path;
|
||||
|
||||
foreach( $uploadFiles as $file )
|
||||
{
|
||||
if( is_file($file) )
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Separator
|
||||
*/
|
||||
protected function _separator($key)
|
||||
{
|
||||
if( $set = ($this->settings[$key] ?? NULL) )
|
||||
{
|
||||
return explode('|', strtolower($set));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* protected get file extension
|
||||
*/
|
||||
protected function getFileExtension($name)
|
||||
{
|
||||
return (($ext = pathinfo($name, PATHINFO_EXTENSION)) ? '.' . $ext : NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Upload
|
||||
*/
|
||||
protected function _upload($rootDir, $root, $src, $nm, $extensions, $mimes, $encryption)
|
||||
{
|
||||
if( empty($nm) )
|
||||
{
|
||||
return ! $this->manuelError = 4; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( $convertName = ($this->settings['convertName'] ?? NULL) )
|
||||
{
|
||||
# 5.4.3[edited]
|
||||
if( $convertName === true )
|
||||
{
|
||||
$nm = Converter::slug($nm, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$nm = $convertName . $this->getFileExtension($nm);
|
||||
}
|
||||
}
|
||||
|
||||
if( empty($encryption) )
|
||||
{
|
||||
if( $this->settings['encode'] ?? NULL )
|
||||
{
|
||||
$encryption = $this->_encode();
|
||||
}
|
||||
else
|
||||
{
|
||||
if( is_file($root.$nm) )
|
||||
{
|
||||
$encryption = $this->_encode(); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$encryptionName = $encryption . $nm;
|
||||
$target = $root . $encryptionName;
|
||||
|
||||
if( is_array($_FILES[$this->file]['name']) )
|
||||
{
|
||||
$this->encodeName = Arrays\AddElement::last((array) $this->encodeName, $encryptionName);
|
||||
$this->path = Arrays\AddElement::last((array) $this->path , $target );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->encodeName = $encryptionName;
|
||||
$this->path = $target;
|
||||
}
|
||||
|
||||
if( ! empty($extensions) && ! in_array(strtolower(pathinfo($nm, PATHINFO_EXTENSION)), $extensions) )
|
||||
{
|
||||
return $this->extensionControl = $this->getLang['upload:extensionError'];
|
||||
}
|
||||
elseif( ! empty($mimes) && ! in_array(Mime::type($src), $mimes) )
|
||||
{
|
||||
return $this->extensionControl = $this->getLang['upload:mimeError'];
|
||||
}
|
||||
elseif( ! empty($maxsize = Converter::toBytes($this->settings['maxsize'] ?? 0)) && $maxsize < filesize($src) )
|
||||
{
|
||||
return $this->manuelError = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ! is_file($rootDir) )
|
||||
{
|
||||
return move_uploaded_file($src, $target);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ! $this->manuelError = 9; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Encode
|
||||
*/
|
||||
protected function _encode()
|
||||
{
|
||||
$encode = $this->settings['encode'];
|
||||
$length = $this->settings['encodeLength'];
|
||||
|
||||
if( ! IS::hash($encode) )
|
||||
{
|
||||
$encode = 'md5';
|
||||
}
|
||||
|
||||
return substr(Encode\Type::create(uniqid(rand()), $encode), 0, $length).'-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Default
|
||||
*/
|
||||
protected function _default()
|
||||
{
|
||||
$this->settings =
|
||||
[
|
||||
'encode' => 'md5',
|
||||
'encodeLength' => 8,
|
||||
'extensions' => [],
|
||||
'mimes' => [],
|
||||
'convertName' => true,
|
||||
'prefix' => NULL,
|
||||
'maxsize' => NULL
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php namespace ZN\Filesystem;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
interface UploadInterface
|
||||
{
|
||||
/**
|
||||
* Uplaod progress
|
||||
*
|
||||
* @param string $selector
|
||||
* @param string $source
|
||||
* @param callable $callable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function progress(string $selector, string $source, callable $callable) : string;
|
||||
|
||||
/**
|
||||
* Is file input name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFile(string $name) : bool;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function settings(array $settings = []) : Upload;
|
||||
|
||||
/**
|
||||
* Sets extensions
|
||||
*
|
||||
* @param string ...$args
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function extensions(...$args) : Upload;
|
||||
|
||||
/**
|
||||
* Sets mimes
|
||||
*
|
||||
* @param string ...$args
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function mimes(...$args) : Upload;
|
||||
|
||||
/**
|
||||
* Sets convert name
|
||||
*
|
||||
* @param string|bool $convert = true
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function convertName($convert = true) : Upload;
|
||||
|
||||
/**
|
||||
* Defines encode type
|
||||
*
|
||||
* @param string $hash = 'md5'
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function encode(string $hash = 'md5') : Upload;
|
||||
|
||||
/**
|
||||
* Sets prefix
|
||||
*
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function prefix(string $prefix) : Upload;
|
||||
|
||||
/**
|
||||
* Sets maxsize
|
||||
*
|
||||
* @param string|int $maxsize = 0
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function maxsize($maxsize = 0) : Upload;
|
||||
|
||||
/**
|
||||
* Sets encode length
|
||||
*
|
||||
* @param int $encodeLength = 8
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function encodeLength(int $encodeLength = 8) : Upload;
|
||||
|
||||
/**
|
||||
* Sets target
|
||||
*
|
||||
* @param string $target
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function target(string $target) : Upload;
|
||||
|
||||
/**
|
||||
* Sets source
|
||||
*
|
||||
* @param string $source = 'upload'
|
||||
*
|
||||
* @return Upload
|
||||
*/
|
||||
public function source(string $source = 'upload') : Upload;
|
||||
|
||||
/**
|
||||
* Start file upload
|
||||
*
|
||||
* @param string $fileName = 'upload'
|
||||
* @param string $rootDir = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function start(string $fileName = 'upload', ?string $rootDir = NULL) : bool;
|
||||
|
||||
/**
|
||||
* Gets info
|
||||
*
|
||||
* @param string $info = NULL
|
||||
*
|
||||
* @return object|false
|
||||
*/
|
||||
public function info(?string $info = NULL);
|
||||
|
||||
/**
|
||||
* Gets error
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function error();
|
||||
|
||||
/**
|
||||
* Clean
|
||||
*/
|
||||
public function clean();
|
||||
}
|
||||
Reference in New Issue
Block a user