FileApiPhp
extends FileApi
in package
File interaction throughout PHP
Table of Contents
Properties
Methods
- __construct() : mixed
- clonePost() : bool
- Copy file to specific array space
- copy() : bool
- Copy file or directory
- createDir() : bool
- Create directory
- createFile() : bool
- Create file
- cropPath() : string
- Remove current $path from inserted path
- delete() : bool
- Delete file or directory
- downloadFile() : bool
- Download file to client
- escape() : string
- Escape filename and add quotes
- exist() : bool
- File exists
- fakeUpload() : void
- Setup $_FILE input
- filterPath() : string
- Remove /../ up directory from url
- fixPath() : string
- Add DIRECTORY_SEPARATOR
- getError() : string
- Return last error message
- getMime() : string
- Get file MIME type
- getPath() : string
- Return current path
- getSize() : int
- Get file size
- getUpload() : mixed
- Get info form $_FILES
- getUrlData() : string|null
- Get file with CURL
- isUpload() : bool
- Check if uploaded file is ok
- isWritable() : bool
- Is it possible to write into filename
- loadFiles() : array<string, array{NAME: string, DATE: int, SIZE: int, MIME: string}>
- Get list of files in directory
- makePath() : string
- Return full formatted path with $dir
- move() : bool
- Move (rename) file or directory
- rename() : bool
- Rename file
- setPath() : bool
- Set current path if exists
- setUpload() : void
- Set value in $_FILES
- upload() : bool
- File upload. Error message is from isUpload
- dirDelete() : bool
- Delete directory
- dirMake() : bool
- Create directory
- fileCopy() : bool
- DirOld for TMP file
- fileDelete() : bool
- Delete file
- getMsg() : string
- Get message text
- processAction() : bool
- Process action form Copy and Move
- uniRename() : bool
- Rename file or directory
Properties
$mode
public
static int
$mode
= 0777
Linux rights for directories
$msgs
public
static array<string, string>
$msgs
= ['FILE' => 'Soubor', 'DIR' => 'Složka', 'NO_UPLOAD' => 'Nebyl zadán soubor pro nahrání.', 'UPLOAD_MAX_SIZE' => 'Soubor %s překročil maximální velikost.', 'UPLOAD_STOPPED' => 'Nahrávání souboru %s bylo přerušeno.', 'UPLOAD_ERROR' => 'Soubor %1$s nelze nahrát (chyba %2$d).', 'NO_RIGHTS' => 'Nemáte právo zápisu do: %s.', 'NO_NAME' => 'Nebyl zadán nový název.', 'EXIST' => ' %s již existuje.', 'NOT_EMPTY' => ' %s není prázdný.', 'NOT_FOUND' => ' %s nenalezena.', 'NOT_MOVE' => ' %s nelze zkopírovat.', 'NOT_COPY' => ' %s nelze přesunout.', 'NOT_RENAME' => ' %s nelze přejmenovat.', 'NOT_DELETE' => ' %s nelze odstranit.', 'CURL_ERROR' => 'Curl error: %d', 'GENERAL_ERROR' => 'General error: %s']
$error
protected
string
$error
= ''
$location
protected
string
$location
$path
protected
string
$path
= ''
Methods
__construct()
public
__construct(string $loc) : mixed
Parameters
- $loc : string
Tags
clonePost()
Copy file to specific array space
public
clonePost(string $fromMark, array<int, mixed>|int|null $fromLevels, string $toMark, array<int, mixed>|int|null $toLevels) : bool
Parameters
- $fromMark : string
- $fromLevels : array<int, mixed>|int|null
- $toMark : string
- $toLevels : array<int, mixed>|int|null
Return values
boolcopy()
Copy file or directory
public
copy(string $dirOld, string $dirNew[, string|null $fileOld = null ][, string|null $fileNew = null ]) : bool
Parameters
- $dirOld : string
- $dirNew : string
- $fileOld : string|null = null
- $fileNew : string|null = null
Return values
boolcreateDir()
Create directory
public
createDir(string $dir) : bool
Parameters
- $dir : string
Return values
boolcreateFile()
Create file
public
createFile(string $dir, string $file, string $data[, bool $replace = false ]) : bool
Parameters
- $dir : string
- $file : string
- $data : string
- $replace : bool = false
Return values
boolcropPath()
Remove current $path from inserted path
public
cropPath(string $dir) : string
Parameters
- $dir : string
Return values
stringdelete()
Delete file or directory
public
delete(string $dir[, string|null $file = null ]) : bool
Parameters
- $dir : string
- $file : string|null = null
Return values
booldownloadFile()
Download file to client
public
downloadFile(string $dir, string $file[, bool $stream = false ]) : bool
Parameters
- $dir : string
- $file : string
- $stream : bool = false
Return values
boolescape()
Escape filename and add quotes
public
static escape(string $value[, string $quote = "'" ]) : string
Parameters
- $value : string
- $quote : string = "'"
Return values
stringexist()
File exists
public
exist(string $dir[, string|null $file = null ][, bool $caseSensitive = false ]) : bool
Parameters
- $dir : string
- $file : string|null = null
- $caseSensitive : bool = false
Return values
boolfakeUpload()
Setup $_FILE input
public
fakeUpload(string $input, string $filePath, string $name[, int|null $id = null ]) : void
Parameters
- $input : string
- $filePath : string
- $name : string
- $id : int|null = null
Tags
filterPath()
Remove /../ up directory from url
public
filterPath(string $dir) : string
Parameters
- $dir : string
Return values
stringfixPath()
Add DIRECTORY_SEPARATOR
public
fixPath(string $dir[, bool $isDir = true ]) : string
Parameters
- $dir : string
- $isDir : bool = true
Return values
stringgetError()
Return last error message
public
getError() : string
Return values
stringgetMime()
Get file MIME type
public
getMime(string $url) : string
Parameters
- $url : string
Return values
stringgetPath()
Return current path
public
getPath() : string
Return values
stringgetSize()
Get file size
public
getSize(string $url) : int
Parameters
- $url : string
Return values
intgetUpload()
Get info form $_FILES
public
getUpload(string $input, string $type[, int|null $id = null ]) : mixed
Parameters
- $input : string
- $type : string
- $id : int|null = null
getUrlData()
Get file with CURL
public
getUrlData(string $url) : string|null
Parameters
- $url : string
Return values
string|nullisUpload()
Check if uploaded file is ok
public
isUpload(string $input[, int|null $id = null ][, bool $emptyIsOk = false ]) : bool
Parameters
- $input : string
- $id : int|null = null
- $emptyIsOk : bool = false
Return values
boolisWritable()
Is it possible to write into filename
public
isWritable(string $url) : bool
Parameters
- $url : string
Return values
boolloadFiles()
Get list of files in directory
public
loadFiles([string $dir = '' ]) : array<string, array{NAME: string, DATE: int, SIZE: int, MIME: string}>
Parameters
- $dir : string = ''
Return values
array<string, array{NAME: string, DATE: int, SIZE: int, MIME: string}>makePath()
Return full formatted path with $dir
public
makePath(string $dir[, bool $isDir = true ]) : string
Parameters
- $dir : string
- $isDir : bool = true
Return values
stringmove()
Move (rename) file or directory
public
move(string $dirOld, string $dirNew[, string|null $fileOld = null ][, string|null $fileNew = null ]) : bool
Parameters
- $dirOld : string
- $dirNew : string
- $fileOld : string|null = null
- $fileNew : string|null = null
Return values
boolrename()
Rename file
public
rename(string $dir, string $oldFile, string $newFile) : bool
Parameters
- $dir : string
- $oldFile : string
- $newFile : string
Return values
boolsetPath()
Set current path if exists
public
setPath(string $dir) : bool
Parameters
- $dir : string
Return values
boolsetUpload()
Set value in $_FILES
public
setUpload(string $input, string $type, mixed $val[, int|null $id = null ]) : void
Parameters
- $input : string
- $type : string
- $val : mixed
- $id : int|null = null
upload()
File upload. Error message is from isUpload
public
upload(string $input, int|null $id, string $dir[, string|null $file = null ][, bool $copy = false ]) : bool
Parameters
- $input : string
- $id : int|null
- $dir : string
- $file : string|null = null
- $copy : bool = false
Return values
booldirDelete()
Delete directory
protected
dirDelete(string $dir) : bool
Parameters
- $dir : string
Return values
booldirMake()
Create directory
protected
dirMake(string $dir) : bool
Parameters
- $dir : string
Return values
boolfileCopy()
DirOld for TMP file
protected
fileCopy(string|null $dirOld, string $dirNew, string $fileOld, string $fileNew) : bool
Parameters
- $dirOld : string|null
- $dirNew : string
- $fileOld : string
- $fileNew : string
Return values
boolfileDelete()
Delete file
protected
fileDelete(string $dir, string $file) : bool
Parameters
- $dir : string
- $file : string
Return values
boolgetMsg()
Get message text
protected
getMsg(string $msg[, string|int|null $param = null ][, string|null $type = null ][, int|null $num = null ]) : string
Parameters
- $msg : string
- $param : string|int|null = null
- $type : string|null = null
- $num : int|null = null
Return values
stringprocessAction()
Process action form Copy and Move
protected
processAction(string $dirOld, string $dirNew, string|null $fileOld, string|null $fileNew[, bool $copy = false ]) : bool
Parameters
- $dirOld : string
- $dirNew : string
- $fileOld : string|null
- $fileNew : string|null
- $copy : bool = false
Return values
booluniRename()
Rename file or directory
protected
uniRename(string $dirOld, string $dirNew, string|null $fileOld, string|null $fileNew) : bool
Parameters
- $dirOld : string
- $dirNew : string
- $fileOld : string|null
- $fileNew : string|null