fyre/filesystem

A file/folder library.

v2.0.7 2024-10-28 08:05 UTC

This package is auto-updated.

Last update: 2024-10-28 08:06:16 UTC


README

FyreFileSystem is a free, open-source file/folder library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/filesystem

In PHP:

use Fyre\FileSystem\File;
use Fyre\FileSystem\Folder;

Files

  • $path is a string representing the file path.
  • $create is a boolean indicating whether to create the file if it doesn't exist, and will default to false.
$file = new File($path, $create);

Access Time

Get the file access time.

$accessTime = $file->accessTime();

Base Name

Get the filename.

$baseName = $file->baseName();

Chmod

Change the file permissions.

  • $permissions is a number representing the file permissions.
$file->chmod($permissions);

Close

Close the file handle.

$file->close();

Contents

Get the contents of the file.

$contents = $file->contents();

Copy

Copy the file to a new destination.

  • $destination is a string representing the destination path.
  • $overwrite is a boolean indicating whether to overwrite an existing file, and will default to true.
$file->copy($destination, $overwrite);

Create

Create the file.

$file->create();

Csv

Parse CSV values from a file.

  • $length is a number representing the maximum line length, and will default to 0.
  • $separator is a string representing the field separator, and will default to ",".
  • $enclosure is a string representing the field enclosure character, and will default to """.
  • $escape is a string representing the escape character, and will default to "\".
$data = $file->csv($length, $separator, $enclosure, $escape);

Delete

Delete the file.

$file->delete();

Dir Name

Get the directory name.

$dirName = $file->dirName();

Ended

Determine whether the pointer is at the end of the file.

$ended = $file->ended();

Exists

Determine whether the file exists.

$exists = $file->exists();

Extension

Get the file extension.

$extension = $file->extension();

File Name

Get the filename (without extension).

$fileName = $file->fileName();

Folder

Get the Folder.

$folder = $file->folder();

Group

Get the file group.

$group = $file->group();

Is Executable

Determine whether the file is executable.

$isExecutable = $file->isExecutable();

Is Readable

Determine whether the file is readable.

$isReadable = $file->isReadable();

Is Writable

Determine whether the file is writable.

$isWritable = $file->isWritable();

Lock

Lock the file handle.

  • $operation is a number representing the lock operation, and will default to LOCK_SH.
$lock = $file->lock($operation);

MIME Type

Get the MIME content type.

$mimeType = $file->mimeType();

Modified Time

Get the file modified time.

$modifiedTime = $file->modifiedTime();

Open

Open a file handle.

  • $mode is a string representing the access mode, and will default to "r".
$open = $file->open($mode);

Owner

Get the file owner.

$owner = $file->owner();

Path

Get the full path to the file.

$path = $file->path();

Permissions

Get the file permissions.

$permissions = $file->permissions();

Read

Read file data.

  • $length is a number representing the number of bytes to read.
$data = $file->read($length);

Rewind

Rewind the pointer position.

$file->rewind();

Seek

Move the pointer position.

  • $offset is a number representing the pointer position.
$file->seek($offset);

Size

Get the size of the file (in bytes).

$size = $file->size();

Tell

Get the current pointer position.

$offset = $file->tell();

Touch

Touch the file.

  • $time is a number representing the modified timestamp, and will default to time().
  • $accessTime is a number representing the access timestamp, and will default to $time.
$file->touch($time, $accessTime);

Truncate

Truncate the file.

  • $size is a number representing the size to truncate to, and will default to 0.
$file->truncate($size);

Unlock

Unlock the file handle.

$file->unlock();

Write

Write data to the file.

  • $data is a string representing the data to write.
$file->write($data);

Folders

  • $path is a string representing the folder path.
  • $create is a boolean indicating whether to create the folder if it doesn't exist, and will default to false.
  • $permissions is a number representing the permissions to create the folder with, and will default to 0755.
$folder = new Folder($path, $create, $permissions);

Contents

Get the contents of the folder.

$contents = $folder->contents();

This method will return an array containing the contents of the folder, as File and Folder objects.

Copy

Copy the folder to a new destination.

  • $destination is a string representing the destination path.
  • $overwrite is a boolean indicating whether to overwrite existing files, and will default to true.
$folder->copy($destination, $overwrite);

Create

Create the folder.

  • $permissions is a number representing the permissions to create the folder with, and will default to 0755.
$folder->create($permissions);

Delete

Delete the folder (including all contents).

$folder->delete();

Empty

Empty the folder.

$folder->empty();

Exists

Determine whether the folder exists.

$exists = $folder->exists();

Is Empty

Determine whether the folder is empty.

$isEmpty = $folder->isEmpty();

Move

Move the folder to a new destination.

  • $destination is a string representing the destination path.
  • $overwrite is a boolean indicating whether to overwrite existing files, and will default to true.
$folder->move($destination, $overwrite);

Name

Get the folder name.

$name = $folder->name();

Path

Get the full path to the folder.

$path = $folder->path();

Size

Get the size of the folder (in bytes).

$size = $folder->size();