HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/public_html/src/core/Directus/Filesystem/Filesystem.php
<?php

namespace Directus\Filesystem;

use Directus\Filesystem\Exception\ForbiddenException;
use League\Flysystem\FilesystemInterface as FlysystemInterface;
use Slim\Http\UploadedFile;

class Filesystem
{
    /**
     * @var FlysystemInterface
     */
    private $adapter;

    public function __construct(FlysystemInterface $adapter)
    {
        $this->adapter = $adapter;
    }

    /**
     * Check whether a file exists.
     *
     * @param string $path
     *
     * @return bool
     */
    public function exists($path)
    {
        return $this->adapter->has($path);
    }

    /**
     * Reads and returns data from the given location
     *
     * @param $location
     *
     * @return bool|false|string
     *
     * @throws \Exception
     */
    public function read($location)
    {
        return $this->adapter->read($location);
    }

    /**
     * Returns a readable stream for the given location
     *
     * @param string $location
     * @return false|resource
     * @throws \League\Flysystem\FileNotFoundException
     */
    public function readStream($location)
    {
        return $this->adapter->readStream($location);
    }

    /**
     * Writes data to the given location
     *
     * @param string $location
     * @param string|UploadedFile $data
     * @param bool $replace
     */
    public function write($location, $data, $replace = false)
    {
        $throwException = function () use ($location) {
            throw new ForbiddenException(sprintf('No permission to write: %s', $location));
        };

        if ($replace === true && $this->exists($location)) {
            $this->getAdapter()->delete($location);
        }

        try {
            if (is_object($data)) { // Uploaded file is in resource format. Used when file uploaded in multipart form data.
                $handle = fopen($data->file, 'rb');
                if (!$this->getAdapter()->writeStream($location, $handle)) {
                    $throwException();
                }
                if (is_resource($handle)) {
                    fclose($handle);
                }
            } else { // Uploaded file is base64 format. Used when file uploaded as base64.
                if (!$this->getAdapter()->write($location, $data)) {
                    $throwException();
                }
            }
        } catch (\Exception $e) {
            $throwException();
        }
    }

    /**
     * Get the filesystem adapter (flysystem object)
     *
     * @return FlysystemInterface
     */
    public function getAdapter()
    {
        return $this->adapter;
    }

    /**
     * Get Filesystem adapter path
     *
     * @param string $path
     * @return string
     */
    public function getPath($path = '')
    {
        /** @var \League\Flysystem\AdapterInterface $adapter */
        $adapter = $this->adapter->getAdapter();

        if ($path) {
            return $adapter->applyPathPrefix($path);
        }

        return $adapter->getPathPrefix();
    }
}