When a new image assets is uploaded the default path to the file is format year folder, month folder and day folder. And what if I want to insert all images into only one folder without sub-folder and dates, is there possible? What file should I edit?
The date format is hardcoded in assets.php, but you can use the cockpit.assets.save
event to rename the paths. You can use this code in /config/bootstrap.php
$app->on('cockpit.assets.save', function(&$assets) {
// new folder for uploads:
// cockpit/storage/uploads/my-assets-folder
$myAssetsFolder = 'my-assets-folder';
foreach ($assets as &$asset) {
$fileName = basename($asset['path']);
$file = $this->path('#uploads:') . ltrim($asset['path'], '/');
$newFile = $this->path('#uploads:') . $myAssetsFolder . '/' . $fileName;
if (rename($file, $newFile)) {
// overwrite assets meta to new path
$asset['path'] = '/' . $myAssetsFolder . '/' . $fileName;
};
}
// remove empty subfolders - /lib/Lime/Helper/Filesystem.php - line 252
$this('fs')->removeEmptySubFolders('#uploads:');
});