Skip to content

Latest commit

 

History

History
83 lines (51 loc) · 1.81 KB

files.md

File metadata and controls

83 lines (51 loc) · 1.81 KB

Working With Files

Contents

Reading Files

Getting the contents of a file:

$contents = File::get('path/to/file');

Writing Files

Writing to a file:

File::put('path/to/file', 'file contents');

Appending to a file:

File::append('path/to/file', 'appended file content');

File Uploads

Moving a $_FILE to a permanent location:

Input::upload('picture', 'path/to/pictures');

Note: You can easily validate file uploads using the Validator class.

File Extensions

Getting the extension from a filename:

File::extension('picture.png');

Checking File Types

Determining if a file is given type:

if (File::is('jpg', 'path/to/file.jpg'))
{
	//
}

The is method does not simply check the file extension. The Fileinfo PHP extension will be used to read the content of the file and determine the actual MIME type.

Note: You may pass any of the extensions defined in the application/config/mimes.php file to the is method.

Getting MIME Types

Getting the MIME type associated with an extension:

echo File::mime('gif');

Note: This method simply returns the MIME type defined for the extension in the application/config/mimes.php file.

Copying Directories

Recursively copy a directory to a given location:

File::cpdir($directory, $destination);

Removing Directories

Recursively delete a directory:

File::rmdir($directory);