Andrew13\Cabinet\CabinetUpload::getUploadFolder PHP Method

getUploadFolder() public method

Get upload path with date folders
public getUploadFolder ( $date = null ) : string
$date
return string
    public function getUploadFolder($date = null)
    {
        // Check that a date was given
        if (is_null($date)) {
            $date = Carbon::now();
        } elseif (!is_a($date, 'Carbon')) {
            throw new InvalidArgumentException('Must me a Carbon object');
        }
        // Get the configuration value for the upload path
        $path = static::$app['config']->get('cabinet::upload_folder');
        $path = $this->cleanPath($path);
        // Add the project base to the path
        $path = static::$app['path.base'] . $path;
        $this->dateFolderPath = str_replace('-', '/', $date->toDateString()) . '/';
        // Parse in to a folder format. 2013:03:30 -> 2013/03/30/{filename}.jpg
        $folder = $path . $this->dateFolderPath;
        // Check to see if the upload folder exists
        if (!File::exists($folder)) {
            // Try and create it
            if (!File::makeDirectory($folder, static::$app['config']->get('cabinet::upload_folder_permission_value'), true)) {
                throw new FileException('Directory is not writable. Please make upload folder writable.');
            }
        }
        // Check that the folder is writable
        if (!File::isWritable($folder)) {
            throw new FileException('Folder is not writable.');
        }
        return $folder;
    }