Download the PHP package martinmuzatko/filehandler without Composer
On this page you can find all versions of the php package martinmuzatko/filehandler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martinmuzatko/filehandler
More information about martinmuzatko/filehandler
Files in martinmuzatko/filehandler
Package filehandler
Short Description Creating, Reading, Writing, Deleting Files & More, see https://github.com/MartinMuzatko/FileHandler
License MIT
Homepage https://github.com/MartinMuzatko/FileHandler
Informations about the package filehandler
FileHandler
As lazy I am, when it comes to php function redundancy, I prefer to create my own tools rather than retyping the entire file open call over and over again.
I am using this self-made FileHandler for years now, and I still can't find a viable alternative.
Optional Requirements
Make sure to enable finfo (fileinfo) php extension to get and in
Installing
Via Composer:
or add it as dependency:
Usage
Include the files or use autoloader.
Using the methods below, you can easily create, write, rename, read files. While FileHandler is a set of static methods, File serves a convenient way of quickly modifying files.
FileHandler Examples
Checking Image Dimensions
File Examples
Batch creating customer directories
Constants
- TAB
- Linefeed (LF)
- Carriage Return (CR)
- Windows Combination (CRLF)
Methods
FileHandler (Static)
Methods are called statically (FileHandler::getInfo())
getInfo($file)
Return fileinformation as object Example:
Returns these informations:
Paths
- dirname
- basename
- extension
- filename
- path
Dimensions
- width
- height
Timestamps and other Properties
- created
- modified
- size
- type
- mimetype (only with finfo enabled)
- encoding (only with finfo enabled)
Permissions
- owner
- group
- perms
Checks - Boolean
- writable
- readable
- exists
- isfile
- isdir
- islink
getAsArray($file)
Returns file content as array.
read($file)
Return File as string if it exists
write($file, $content, $seperator = CRLF)
Overwrites File with given string or array, returns true if succeeded.
create($file, $content = '')
Creates File but does not overwrite existing files.
delete($file)
Delete file if existing.
rename($old, $new)
Rename a File from old path to new path
appendFile($targetFile, $file, $seperator = CRLF)
Appends $file to $targetFile with given seperator.
appendLine($targetFile, $content, $seperator = CRLF)
Appends $content to $targetFile with a defined $seperator
clearFile($file)
Clears file from any content
listFiles($path = '.', $includeFiles = true, $includeFolders = true)
List all files within a valid directory as array
File (Method Chaining)
The constructor and some other methods accepts any of these:
- Instance of File
- String (Paths)
- Resources (Handles retrieved by )
- Any other kind of File Stream
After constructing, the File contains ANY info retrievable via e.g.
create()
Create file, accepts no param, file is entered via constructur:
copy($target)
delete()
rename($name)
move($target)
Moving file to desired location, will automatically create all directories needed for new location example:
will move index.php to and will create the folders , and
chmod($octet)
Changing the file permissions from 0111 to 0777
merge($target) work in progress
read()
Get file contents. Method chaining after calling this method is not possible anymore.
concat($content, $separator = CRLF)
Adding content to a file.
write($content)
Write as in overwrite (use concat if you want to add to the file instead of overwriting)
find($lookup)
Find files in a directory, regex enabled. Retrievable via or
EXAMPLES:
Find by string:
Find by Regex:
Find by Property - Value pairs with operators:
-
find all files of mimetype image/png
-
find all files smaller than 600KB
-
fild all files newer than 31.08.2015
- fild all non-directory files
Operators: <, >, <=, >=, !
Properties are used by getInfo()
get()
This method is used as final method to get selections made by find() or select() or new File() Returns path if no selection is done.
select()
Selecting files by paths array of paths array of Files array of File Selections You can also mix these
Examples
Any array or array of arrays will be traversed down to create an one-dimensional array saved to public property $selection. Selections are retrievable by get()