GithubHelp home page GithubHelp logo

filesystem's Introduction

FileSystem

Scrutinizer Code Quality

Helper functions to work with the file system.

Files

<?php

$file = new SugiPHP\FileSystem\Files();

// Checks the existence of file with a given filename
$file->exists($filename);

// Determine if the file can be opened for reading
$file->isReadable($filename);

// Determine if the file can be opened for writing
$file->isWritable($filename);

// Trying to get the contents of the file. The file must exists and
//  must be readable. If not - the default value is returned.
$contents = $file->get($filename, $default = null);
// Returns a default value
$contents = $file->get("unexisting_file", "Your default contents...");
// or you can use read as an alias of get
$contents = $file->read($filename, $default = null);

// Writes data in the file.
// If the file does not exists it will be created.
// If the $mode parameter is set the newly created file will have mode $mode
// Returns FALSE if operation fails.
$bytes_written = $file->put($filename, $data, $mode = null);
// You can use write alias of put
$bytes_written = $file->write($filename, $data, $mode = null);

// Appends data in the file.
// If the file does not exists it will be created.
// Returns FALSE if operation fails.
$bytes_appended = $file->append($filename, $data);

// Deletes a file. Returns TRUE if the file is successfully removed or didn't exists.
$file->delete($filename);

// Change mode for files. Returns FALSE on error.
$file->chmod($filename, 0664);

// Changes owner of the file. Returns FALSE on error.
// A user can be a user name (string) or a number (UID)
$file->chown($filename, $user);

// Changes group owner of the file. Returns FALSE on error.
// A group can be a string or a number (GID)
$file->chgrp($filename, $group);

// Get extension of the file. Returns false if the file does not exists
$file->ext($filename);

// Returns owner's user ID.
$file->getUID($filename)

// Returns owner's name
$file->getOwner($filanme)

// Returns group ID
$file->getGID($filename)

// Returns group name
$file->getGroup($filename)

// Gets file modification time
$file->mtime($filename)

// Copy file. Returns TRUE if copy is successful.
$file->copy($source, $destination, $overwrite = false);

// Renames / moves a file.
$file->move($source, $destination, $overwrite = false);

// TODO:
// symlink()
// touch()
?>

Directories

<?php

$dir = new SugiPHP\FileSystem\Directories();

// Checks the existence of directory with a given name
$dir->exists($name);

// Determine if the directory can be accessed
$dir->isReadable($name);

// Determine if we can write files in the directory
$dir->isWritable($name);

// Change mode for directories.
$dir->chmod($name, 0755);

// Creates directory recursively.
// If the directory is already created returns TRUE.
// Returns FALSE on failure
$dir->mkdir($name);

?>

filesystem's People

Contributors

tzappa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.