File class

When an instance is created, it is created with a file storage, which can be accessed through the File class.

A file can be added to the store like:

$file = new File();
$file->folder = 'Myfolder';
$file->attachFile('/tmp/realfile.txt');
$file->save();
echo 'File saved with ID: '.$file->file_id;

To get access to the file data afterwards:

$file = new File();
$file->loadForRead($file_id);
 
// Get a psychical path
$file->getCompleteFilename();
 
// Get an URL
$file->getURL();

The file is actually saved in the given folder within the storage, so the folder should be a valid folder name. The folder name can be nested such as folder/subfolder/subsubfolder/.

Reserved folder names

Platform is using some folder names already:

logsThis is used by the Log system to store logs.
tempThis is used by FieldFile form fields to store temporary uploaded files.