MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

MMO\core\files

MMO\core\files · 33 symboles · générée le 27 Oct 2026

function

copy

files.php:497

Copy a file or folder (recursively), returning the number of files actually copied.

function copy(string $from, string $to, ?string $inc = null, ?string $exc = null): int
Espace de noms
MMO\core\files
To inspect each individual file as it's copied, use [`loopCopy()`](https://mmoframework.fr/fr/documentation/mmo.core/php/files.md#loopcopy) directly instead.
$fromstringthe source file/folder
$tostringthe destination
$inc = nullnull | stringa regular expression to select the files to copy
$exc = nullnull | stringa regular expression to exclude the files from being copied
retourneintthe number of files copied
copy('/src/folder', '/dst/folder'); // copies everything, returns the file count
Graphe d'appels
function

createDir

files.php:112

Create a folder (recursively) if it does not exist.

function createDir(string $dir, ?int $perms = null): bool
Espace de noms
MMO\core\files
$dirstringthe folder path
$perms = nullnull | intthe permission to give to the folder. if null, will use its parent permission.
retournebooltrue if the folder is created, false if the folder already exists.
Graphe d'appels
function

csv

files.php:758

Read and decode a CSV file (a UTF-8 BOM, if present, is stripped first). csvDecode().

function csv( $resource, array|bool $keys = true, string $separator = ';', string $enclosure = '"', string $escape = '\\', ?string $lineSep = MMO\core\files\PHP_EOL ): array
Espace de noms
MMO\core\files
WARNING: a trailing newline at the end of the file content (common -- most text files end with one) produces a spurious extra all-null trailing row; [`csvDecode()`](https://mmoframework.fr/fr/documentation/mmo.core/php/strings.md#csvdecode) for the underlying cause.
$resourcethe filename, or an open handle on the file
$keys = truearray | boolif true, the first row is used as column names for every other row; if an array, used directly as column names (every row, including the first, is then data)
$separator = ';'stringthe field delimiter
$enclosure = '"'stringthe field quoting character
$escape = '\\'stringthe escape character
$lineSep = MMO\core\files\PHP_EOLnull | stringthe line separator
retournearray
csv('/tmp/data.csv'); // [['col1' => 'a', 'col2' => 'b']] for a file containing "col1;col2\na;b" (no trailing newline)
Graphe d'appels

Utilise (2)

Utilisé par (1)

function

dataURI

files.php:686

Encode a file as a data: URI (its content, base64-encoded, with its detected mime type), ready to use directly as e.g. an <img src="...">.

function dataURI(string $filename): string
Espace de noms
MMO\core\files
$filenamestring
retournestring
dataURI('/tmp/tiny.txt'); // e.g. 'data: text/plain;base64,aGk='
Graphe d'appels

Utilise (1)

function

dataURIToFile

files.php:716

Reverse of dataURI(): decode a data: URI and write its content to $filename.

function dataURIToFile(string $filename, string $data): string
Espace de noms
MMO\core\files
$filenamestring
$datastringa full data:mime/type;base64,... URI
retournestringthe mime type extracted from $data
lèveif $data isn't a base64 data URI
dataURIToFile('/tmp/out.txt', 'data: text/plain;base64,aGk='); // writes 'hi', returns 'text/plain'
Graphe d'appels

Utilise (1)

Utilisé par (1)

function

delete

files.php:544

Recursively delete a file or folder. To inspect each individual path as it's deleted, use loopDelete() directly.

function delete(string $path, ?string $inc = null, ?string $exc = null): void
Espace de noms
MMO\core\files
$pathstringthe file/folder to delete
$inc = nullnull | stringa regular expression to select which entries to delete
$exc = nullnull | stringa regular expression to exclude entries from being deleted
retournevoid
delete('/some/dir');
Graphe d'appels
function

exists

files.php:578

Test if a local file, or a remote url (via a curl HEAD request), exists/is reachable.

function exists(string $url): bool
Espace de noms
MMO\core\files
$urlstring
retournebool
exists('/etc/hostname'); // true (for a local file); a remote url is checked via a curl HEAD request
Graphe d'appels
function

filename

files.php:266

Get the underlying filename (for a stream) or command (for a process) of a resource.

function filename($var)
Espace de noms
MMO\core\files
$vara stream or process resource
retournefalse if $var isn't a stream/process resource, or has no known uri/command
filename(fopen('/tmp/x', 'w')); // '/tmp/x'
Graphe d'appels

Utilisé par (1)

function

get

files.php:357

Read the content of a file (given as a filename, read directly) or an already-open stream resource.

function get($stream, ?int $maxlen = null, int $offset = 0): string
Espace de noms
MMO\core\files
$streama filename, or an open stream resource
$maxlen = nullnull | intmaximum number of bytes to read. null for everything.
$offset = 0intthe offset to start reading from
retournestring
lèveif $stream isn't readable
get('/etc/hostname');
Graphe d'appels
function

image

files.php:697

Load an image file (jpeg/png/gif) as a GD image resource/object.

function image(string $filename, ?array &$size = null)
Espace de noms
MMO\core\files
$filenamestring
$size = nullnull | array
retourne
lèveif the image's mime type isn't jpeg/png/gif
function

isLocal

files.php:563

Tells if a uri refers to the local filesystem: no authority at all (a plain path), or a file:///phar:// scheme. Determines whether exists()/mtime() use plain filesystem calls or a curl HEAD request.

function isLocal(string $url): bool
Espace de noms
MMO\core\files
$urlstring
retournebool
isLocal('/local/path'); // true isLocal('file:///local/path'); // true isLocal('https://example.com'); // false
Graphe d'appels
function

isMoreRecent

files.php:640

Tells if a file was modified after $time -- or, for a folder (or an already-obtained loopFolder() generator), if ANY file under it was.

function isMoreRecent( Generator|string $filename, int $time, ?string $inc = null, ?string $exc = null ): bool
Espace de noms
MMO\core\files
$filenameGenerator | stringa filename, or a generator of files (e.g. from loopFolder())
$timeinta unix timestamp to compare against
$inc = nullnull | stringa regular expression of files to include (only used when $filename is a folder)
$exc = nullnull | stringa regular expression of files to exclude (only used when $filename is a folder)
retourneboolfalse if $filename (a single file) doesn't exist
isMoreRecent('/some/dir', time() - 3600); // true if anything in the folder changed in the last hour
Graphe d'appels
function

json

files.php:738

Read and decode a JSON file (jsonDecode() for $asArray/$vars/$cleanUp).

function json( $resource, bool $asArray = true, ?array $vars = null, bool $cleanUp = true ): mixed
Espace de noms
MMO\core\files
$resourcethe filename, or an open handle on the file
$asArray = trueboolif true, a JSON object decodes to a plain PHP array instead of stdClass
$vars = nullnull | arrayvariables to substitute into the JSON before decoding it (a light templating step)
$cleanUp = trueboolif true, tolerate trailing commas and line/block comments (non-standard JSON, not natively supported by PHP)
retournemixed
lèveif the file's content isn't valid (post-cleanup) JSON
json('/tmp/config.json');
Graphe d'appels
function

loopCopy

files.php:467

Recursively copy a file or folder, yielding each individual file as it's copied (a folder itself isn't yielded, only the files under it -- but it IS created, even if empty).

function loopCopy(string $from, string $to, ?string $inc = null, ?string $exc = null)
Espace de noms
MMO\core\files
$fromstringthe source file/folder
$tostringthe destination
$inc = nullnull | stringa regular expression to select the files to copy (loopFolder())
$exc = nullnull | stringa regular expression to exclude files from being copied (loopFolder())
retournestring> yields sourceFile => destFile
lèveif $from doesn't exist
lèveif a copy fails
foreach (loopCopy('/src', '/dst') as $from => $to) {...}
Graphe d'appels

Utilisé par (2)

function

loopDelete

files.php:516

Recursively delete a file or folder (depth-first: a folder's contents are deleted before the folder itself), yielding the path of each thing actually removed as it's removed.

function loopDelete(string $path, ?string $inc = null, ?string $exc = null): Generator
Espace de noms
MMO\core\files
$pathstringthe file/folder to delete
$inc = nullnull | stringa regular expression to select which entries to delete (loopFolder())
$exc = nullnull | stringa regular expression to exclude entries from being deleted (loopFolder())
retourneGeneratoryields each deleted path
lèveif a delete fails
foreach (loopDelete('/some/dir') as $deleted) {...}
Graphe d'appels

Utilisé par (2)

function

loopFolder

files.php:160

Lazily list the entries of a folder (files AND subfolders, each yielded individually -- a subfolder is yielded itself, in addition to whatever's recursed into it).

function loopFolder( string $folder, int|bool $recursive = true, ?string $inc = null, ?string $exc = null, string $_path = '' ): Generator
Espace de noms
MMO\core\files
$folder's last segment can be a glob (a `*`/`**` pattern, e.g. `/some/dir.jpg`) instead of a real folder name: it's resolved automatically by turning it into an $inc regex and listing the parent folder instead -- a single `*.jpg`-style glob also forces $recursive to false, a `**.jpg`-style one forces it to true.
$folderstringthe folder's filename, optionally ending in a glob pattern
$recursive = trueint | boolif true, recurse into every subfolder; if an int, the remaining recursion depth (0 = don't recurse further)
$inc = nullnull | stringa regex the entry's path (relative to $folder) must match to be yielded (null = include everything)
$exc = nullnull | stringa regex that excludes a matching entry (and, if it's a folder, everything under it) entirely
$_path = ''stringinternal: the current path prefix during recursion. Leave at the default.
retourneGeneratorstring> yields relative path => absolute path
lèveif $inc/$exc isn't a valid regex
lèveif $folder doesn't exist (and isn't a resolvable glob)
foreach (loopFolder('/some/dir') as $rel => $abs) {...} // every entry, recursively foreach (loopFolder('/some/dir.jpg') as $rel => $abs) {...} // only *.jpg directly in dir foreach (loopFolder('/some/dir*.jpg') as $rel => $abs) {...} // *.jpg anywhere under dir, recursively
Graphe d'appels
function

move

files.php:664

Move file to new destination

function move(string $from, string $to, bool $overwrite = false): void
Espace de noms
MMO\core\files
$fromstring
$tostring
$overwrite = falseboolif false (default), an existing $to throws instead of being overwritten
retournevoid
lèveif $from doesn't exist
lèveif $to already exists and either $overwrite is false or $to isn't writable
lèveif the move itself fails
move('/tmp/x.tmp', '/data/x.txt');
Graphe d'appels

Utilise (1)

function

mtime

files.php:603

Get a file/url's last-modified time, locally via \filemtime() or remotely via a curl HEAD request.

function mtime(string $url): ?int
Espace de noms
MMO\core\files
$urlstring
retournenull | inta unix timestamp, or null if $url doesn't exist / isn't reachable / doesn't report a filetime
mtime('/etc/hostname'); // e.g. 1704067200
Graphe d'appels

Utilise (2)

function

name

files.php:239

Get a short, human-readable identifier for a stream or process resource (for logging/debugging).

function name($var)
Espace de noms
MMO\core\files
$vara stream or process resource
retourne[type[:mode-or-pid]]uri-or-command, or [unknown]unknown ressource for anything else
name(fopen('/tmp/x', 'w')); // '[STDIO:w]/tmp/x'
Graphe d'appels
function

open

files.php:316

Open a file and return the resulting stream resource, translating the STREAM_* flag bitmask into the right \fopen() mode (always append-mode when writing, so an existing file's content is preserved unless STREAM_CLEAR is also set -- write() which does the truncation).

function open(string $filename, int $flags = MMO\core\files\STREAM_READ)
Espace de noms
MMO\core\files
$filenamestring
$flags = MMO\core\files\STREAM_READinta bitmask of STREAM_READ/STREAM_WRITE/STREAM_CLEAR/STREAM_CREATE_FOLDER/STREAM_BINARY
retourne
lèveif the file cannot be opened (e.g. the target isn't writable)
open('/tmp/x.log', STREAM_WRITE | STREAM_CREATE_FOLDER);
Graphe d'appels
function

package

files.php:821

Package a list of files into a phar package WARNING: when creating a PharData (no stub), the filename MUST NOT have .phar in the extension. Else php throws an Exception.

function package( string $filename, array $files, array|string|null $stub, ?string $alias = null, int $compression = Phar::NONE ): void
Espace de noms
MMO\core\files
$filenamestringthe phar archive's filename
$filesarraythe files to add as localname => content content can be : - a filename - a directory. In this case localname MUST be the relative path contained in the directory to use in the phar: example: src/files => /home/mmo/src/files - a direct string if it starts with =, - a resource (fopen()), - a Traversable (DirectoryIterator)
$stubarray | string | nullthe stub to use depending on the PHP_SAPI constant if it is a simple string, it is used for all. else it has to be an array[regex => name] where regex is used to test PHP_SAPI (* for any) name is the local filename of the file in the phar archive
$alias = nullnull | stringthe local phar alias to use to call flux operation on the archive. by default the basename of the archive.
$compression = Phar::NONEinta \Phar::* compression constant (e.g. \Phar::GZ, \Phar::BZ2)
retournevoid
lèveif phar.readonly is enabled in php.ini, or a file/folder to remove/add fails
package('/build/app.phar', ['src' => '/project/src'], 'src/bootstrap.php');
Graphe d'appels

Utilise (1)

Utilisé par (1)

function

perms

files.php:59

Get a file/folder's permissions formatted like unix ls -l (e.g. 'drwxr-xr-x').

function perms(string $file): ?string
Espace de noms
MMO\core\files
$filestringfilename
retournenull | stringnull if $file doesn't exist
perms('/etc/passwd'); // e.g. '-rw-r--r--'
Graphe d'appels
function

permsText

files.php:70

Format a raw \fileperms()-style integer as a unix ls -l permission string.

function permsText(int $perms): string
Espace de noms
MMO\core\files
$permsint
retournestring
permsText(0100644); // '-rw-r--r--'
Graphe d'appels

Utilisé par (2)

function

put

files.php:432

Same as write(), but always appends and creates any missing parent folder (STREAM_PUT = write + create folder).

function put($stream, string $text)
Espace de noms
MMO\core\files
$stream
$textstring
retourne
put('/tmp/new/subdir/x.log', "line\n"); // creates /tmp/new/subdir/ if needed
Graphe d'appels

Utilise (1)

function

rootFolder

files.php:211

Get the deepest common ancestor folder shared by a list of filenames.

function rootFolder(array $files): string
Espace de noms
MMO\core\files
$filesarraythe files (at least one; absolute paths)
retournestringends with a trailing '/'. '/' itself if the files share no common folder beyond the filesystem root.
rootFolder(['/a/b/c.txt', '/a/b/d.txt', '/a/e.txt']); // '/a/'
function

scanFolder

files.php:199

Same as loopFolder(), but eagerly collects the results into an array, naturally case-insensitively sorted and then REVERSED (so entries come back in descending natural order).

function scanFolder( string $folder, int|bool $recursive = true, ?string $inc = null, ?string $exc = null ): array
Espace de noms
MMO\core\files
$folderstring
$recursive = trueint | bool
$inc = nullnull | string
$exc = nullnull | string
retournearrayrelative path => absolute path, descending natural order
Graphe d'appels
function

set

files.php:421

Same as write(), but always replaces the stream's entire existing content (STREAM_SET = write + clear).

function set($stream, string $text)
Espace de noms
MMO\core\files
$stream
$textstring
retourne
set('/tmp/x.log', 'fresh content'); // overwrites whatever was there
Graphe d'appels
function

size

files.php:445

Format a byte count as a human-readable size, with French unit abbreviations (o/ko/Mo/Go/To).

function size(string|int $bytes, int $decimals = 2): string
Espace de noms
MMO\core\files
$bytesstring | intan int byte count, or a filename to \filesize() first
$decimals = 2intnumber of decimals
retournestring
size(1536); // '1.50 ko' size(1048576); // '1.00 Mo'
function

sort

files.php:135

Sort a list of filenames "naturally" (so 'file2' sorts before 'file10' -- strnatcmp()).

function sort(&$files): array
Espace de noms
MMO\core\files
$files
retournearraythe same array, sorted (also returned for convenience/chaining)
sort($files); // ['file2.txt', 'file10.txt'] stays in that order, not lexicographic
function

temporaryFilename

files.php:287

Create an empty, uniquely-named temporary file (in the {tmp} path alias) and return its filename.

function temporaryFilename(string $prefix = '')
Espace de noms
MMO\core\files
$prefix = ''stringa prefix to use for the filename
retournethe filename
lèveif the file could not be created
Graphe d'appels
function

temporaryFolder

files.php:299

Create an empty, uniquely-named temporary FOLDER (in the {tmp} path alias) and return its filename.

function temporaryFolder(string $prefix = '')
Espace de noms
MMO\core\files
$prefix = ''stringa prefix to use for the folder's name
retournethe folder's filename
lèveif the folder was not created
Graphe d'appels
function

write

files.php:383

Write $text to a stream.

function write($stream, string $text, int $flags = MMO\core\files\STREAM_WRITE)
Espace de noms
MMO\core\files
- if $stream is a filename, the file is opened ([`open()`](https://mmoframework.fr/fr/documentation/mmo.core/php/files.md#open), honoring $flags), written, and closed -- this function then returns null. - if $stream is already an open resource, $text is appended to wherever the stream's cursor currently is (or the stream is truncated back to empty first if $flags includes STREAM_CLEAR); the stream is left open and IS returned, so calls can be chained.
$stream
$textstring
$flags = MMO\core\files\STREAM_WRITEinta bitmask of STREAM_* const, only relevant when $stream is a filename (open())
retourne
lèveif $stream is neither a string nor a resource
lèveon a write error
write('/tmp/x.log', "line\n", STREAM_PUT); // appends, creating the folder/file if needed
Graphe d'appels
function

zip

files.php:773

Open a zip archive, throwing a descriptive exception (rather than returning an error code) on failure.

function zip(string $filename, int $flags): ZipArchive
Espace de noms
MMO\core\files
$filenamestring
$flagsinta bitmask of \ZipArchive::* open flags (e.g. \ZipArchive::CREATE)
retourneZipArchive
lèveif the archive can't be opened
zip('/tmp/archive.zip', \ZipArchive::CREATE);