PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Helper / API Basic

Work with Files and Folders Using Joomla\Filesystem\File and Folder

Replaces removed JFile, JFolder and Joomla\CMS\Filesystem classes with the Joomla\Filesystem Framework package in Joomla 5 and 6.

Updated on 24 November 2026 49 copies 169 views
components/com_example/src/Helper/StorageHelper.php
<?php

declare(strict_types=1);

use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;

$dir = Path::clean(JPATH_ROOT . '/images/exports');
if (!is_dir($dir)) {
    Folder::create($dir);
}

$safeName = File::makeSafe('relatorio 2026!.json');
File::write($dir . '/' . $safeName, json_encode(['ok' => true]));
$files = Folder::files($dir, '\.json$');
Sanitize user-supplied filenames with File::makeSafe() before writing to disk.
components/com_example/src/Helper/StorageHelper.php
<?php
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');

$dir = JPATH_ROOT . '/images/exports';
if (!JFolder::exists($dir)) {
    JFolder::create($dir);
}
JFile::write($dir . '/' . JFile::makeSafe('relatorio.json'), '{"ok":true}');
Legacy Joomla 3 version using jimport, JFile and JFolder.

Technical explanation and best practices

In Joomla 6, legacy Joomla\CMS\Filesystem\* classes were removed in favor of Joomla\Filesystem\File, Folder and Path. Updating these imports is essential for Joomla 6 readiness.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.