The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

Understanding The File Class

The Trongate File class provides a comprehensive suite of methods for efficient and secure file management within your application. This class supports functionalities like uploading, deleting, reading, writing files, and managing directories. Access restrictions are in place to prevent unauthorized access to critical directories such as 'config', 'engine', and 'templates', as well as any files directly under the root application level (e.g., '.htaccess').

Getting Started

To use the Trongate File class, you need to instantiate the class and then call its methods. Here’s a basic example of how to use the read() method:

In the above example, the APPPATH constant is used to return the absolute file path of the application's root directory. Additional information about this and other helpful features are available from here.

The example also uses Trongate's out() function to remove potentially dangerous characters from rendered output.

Available Methods

Below is a table listing all the available methods in the Trongate File class, along with a brief description of each method:

Method Description
copy() Copies a file from one location to another.
create_directory() Creates a new directory at the specified path.
delete() Deletes a file from the filesystem.
download() Initiates a file download or displays inline from the server or an external URL.
exists() Checks whether a file or directory exists at the specified path.
info() Retrieves metadata about a file.
list_directory() Lists files and directories within a specified directory.
move() Moves a file from one location to another.
read() Reads the contents of a file.
upload() Handles the file upload process with specified configuration.
write() Writes or appends data to a file.
×