Skip to content

FileHelper

Mistralys edited this page Apr 29, 2021 · 6 revisions

The file helper, as its name implies, is there to help with file-related operations, but also folders.

Configuration

No configuration needed: the FileHelper is a static class, so all its methods can be accessed statically.

Methods

File related methods

  • copyFile: Copies a file
  • countFileLines: Count the amount of lines in a file
  • deleteFile: Deletes a file
  • detectMimeType: Detects a file's Mime type by its extension
  • detectUTF8Bom: Detects the type of UT8 Byte Order Mark used in a file, if any
  • downloadFile: Downloads a file from an URL
  • findFiles: Search for files by criteria
  • findPHPFiles: Searches for PHP files by criteria
  • getExtension: Gets a file extension from a path or directory iterator
  • getFilename: Gets the file name with extension from a path or directory iterator
  • getFileLine: Fetch a specific line from a file by number
  • getModifiedDate: Gets a DateTime instance of the target's modified date
  • isPHPFile: Whether the target path is a PHP file
  • parseCSVFile: Opens a CSV file and returns the values of all lines in an array
  • parseJSONFile: Opens a JSON file and returns the decoded data array
  • parseSerializedFile: Opens the target file and unserializes its contents to return the data array
  • removeExtension: Removes the extension from a file name
  • saveAsJSON: Saves a data array to a JSON file
  • saveFile: Saves arbitrary data to disk in a file
  • sendFile: Sends a file to the browser to download using the correct mime type

Folder related methods

  • copyTree: Copy a complete folder tree including files
  • createFolder: Create a new folder
  • deleteTree: Delete a complete folder tree including files
  • getSubfolders: Finds all subfolders of the specified folder

Path related methods

  • normalizePath: Converts all slashes in a path to the unix style "/"
  • relativizePath: Cuts off a path to make it relative to another path
  • relativizePathByDepth: Cuts off a path to have a maximum folder depth

System related methods

  • canMakePHPCalls: whether it is possible to call PHP on the command line
  • cliCommandExists: whether the specified command name is available on the command line
  • getMaxUploadFilesize: The size in bytes of the maximum allowed upload file size

Misc methods

  • createCSVParser: Creates an instance of the parseCSV class
  • createFileFinder: Creates an instance of the file finder utility class
  • findPHPClasses: Detects PHP class declarations in the target file, and returns information on them
  • getKnownUnicodeEncodings: Retrieves a list of unicode encoding names, e.g. "UTF-8"
  • getUTFBoms: Retrieves all known UTF Byte Order Mark character sequences
  • isValidUnicodeEncoding: Checks whether an encoding name is valid

New here?

Have a look at the overview for a list of all helper classes available in the package.

Table of contents

Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.

Clone this wiki locally