https://github.com/joomla-framework/filesystem
Joomla Framework Filesystem Package
https://github.com/joomla-framework/filesystem
filesystem joomla joomla-framework php
Last synced: 22 days ago
JSON representation
Joomla Framework Filesystem Package
- Host: GitHub
- URL: https://github.com/joomla-framework/filesystem
- Owner: joomla-framework
- License: gpl-2.0
- Created: 2013-02-24T03:20:00.000Z (about 12 years ago)
- Default Branch: 3.x-dev
- Last Pushed: 2025-03-07T10:20:19.000Z (about 2 months ago)
- Last Synced: 2025-03-28T11:06:13.386Z (29 days ago)
- Topics: filesystem, joomla, joomla-framework, php
- Language: PHP
- Homepage:
- Size: 5.35 MB
- Stars: 10
- Watchers: 13
- Forks: 19
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# The Filesystem Package [](https://ci.joomla.org/joomla-framework/filesystem)
[](https://packagist.org/packages/joomla/filesystem)
[](https://packagist.org/packages/joomla/filesystem)
[](https://packagist.org/packages/joomla/filesystem)
[](https://packagist.org/packages/joomla/filesystem)## File upload example
```php
use Joomla\Filesystem\File;$file = $this->input->files->get('file');
$config = array(
'extensions' => 'jpg,jpeg,gif,png,pdf,doc,docx',
'max_size' => 30000000, // 30 MB
'folder' => 'documents'
);// Check there is some file to upload
if (empty($file['name']))
{
return;
}// Check max size
if ($file['size'] > $config['max_size'])
{
throw new \RuntimeException('Uploaded file size (' . round($file['size'] / 1000) . ' kB) is greater than allowed size (' . round($config['max_size'] / 1000) . ' kB).');
}$config['extensions'] = explode(',', $config['extensions']);
// Get File extension
$ext = strtolower(substr($file['name'], (strrpos($file['name'], '.') + 1)));// Sanitize allowed extensions
foreach ($config['extensions'] as &$extension)
{
$extension = str_replace('.', '', trim(strtolower($extension)));
}// Check allowed extensions
if (!in_array($ext, $config['extensions']))
{
throw new \RuntimeException('Uploaded file extension (' . $ext . ') is not within allowed extensions (' . implode(',', $config['extensions']) . ')');
}$path = JPATH_ROOT . '/' . $config['folder'] . '/' . File::makeSafe($file['name']);
File::upload($file['tmp_name'], $path);
```## Changes From 1.x
### Patcher
In 1.x, the second parameter of the `add` and `addFile` methods was optional. In 2.0, this parameter is required. This parameter requires the
root path of the source which you are patching.## Installation via Composer
Add `"joomla/filesystem": "~3.0"` to the require block in your composer.json and then run `composer install`.
```json
{
"require": {
"joomla/filesystem": "~3.0"
}
}
```Alternatively, you can simply run the following from the command line:
```sh
composer require joomla/filesystem "~3.0"
```If you want to include the test sources, use
```sh
composer require --prefer-source joomla/filesystem "~3.0"
```