Quick links: Content - sections - sub sections

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.


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

// The content of "directory" AND the directory itself will be deleted


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:

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.