Section: jFile: file processing
« jMessage: short messages between actions | ^ Class utilities |
− Table of content
jFile help to do file processing. All methods of jFile are statics, so you don't have to instanciate this class.
read method ¶
It returns the content of a file, or false
if the file doesn't exist.
$content = jFile::read('/path/to/file.ext');
write method ¶
Write data into a file. It uses a temporary file, and then rename it to the given name, in order to limit access conflicts.
It returns true
if it is a success.
jFile::write('/path/to/file.ext', 'my data');
createDir method ¶
Create a directory. If parents don't exist, they are also created.
jFile::createDir('/path/of/the/directory/');
removeDir method ¶
Delete recursively the content of a directory. The second parameter allows to
delete (true
by default) or not (false
) the directory itself.
jFile::removeDir('/path/of/the/directory', false);
// only the content of the directory will be deleted
jFile::removeDir('/path/of/the/directory');
// The content of "directory" AND the directory itself will be deleted
getMimeTypeFromFilename ¶
It allows to know the mime type of a file by analysing its name. It recognizes
many file name extension. However you can add your own extensions into the
mimeTypes
section into the configuration, like this:
[mimeTypes]
foo = "application/foo"
Files having the extension "foo" will be recognized as having the "application/foo" mime type.
Other functions ¶
jFile have other static methods, inherited from other classes of the
package jelix/file-utilities
: \Jelix\FileUtilities\File
, \Jelix\FileUtilities\Path
,
\Jelix\FileUtilities\Directory
... See their API.