mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-07-02 01:19:29 +02:00
Recursive folder creation in Upload
This commit is contained in:
parent
bb6283740a
commit
68af8409a5
|
@ -127,11 +127,8 @@ class Upload extends Controller {
|
||||||
$parentFolder = Folder::find_or_make($folderPath);
|
$parentFolder = Folder::find_or_make($folderPath);
|
||||||
|
|
||||||
// Create a folder for uploading.
|
// Create a folder for uploading.
|
||||||
if(!file_exists(ASSETS_PATH)){
|
|
||||||
mkdir(ASSETS_PATH, Config::inst()->get('Filesystem', 'folder_create_mask'));
|
|
||||||
}
|
|
||||||
if(!file_exists(ASSETS_PATH . "/" . $folderPath)){
|
if(!file_exists(ASSETS_PATH . "/" . $folderPath)){
|
||||||
mkdir(ASSETS_PATH . "/" . $folderPath, Config::inst()->get('Filesystem', 'folder_create_mask'));
|
Filesystem::makeFolder(ASSETS_PATH . "/" . $folderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate default filename
|
// Generate default filename
|
||||||
|
@ -156,24 +153,24 @@ class Upload extends Controller {
|
||||||
|
|
||||||
// if filename already exists, version the filename (e.g. test.gif to test1.gif)
|
// if filename already exists, version the filename (e.g. test.gif to test1.gif)
|
||||||
if(!$this->replaceFile) {
|
if(!$this->replaceFile) {
|
||||||
while(file_exists("$base/$relativeFilePath")) {
|
while(file_exists("$base/$relativeFilePath")) {
|
||||||
$i = isset($i) ? ($i+1) : 2;
|
$i = isset($i) ? ($i+1) : 2;
|
||||||
$oldFilePath = $relativeFilePath;
|
$oldFilePath = $relativeFilePath;
|
||||||
// make sure archives retain valid extensions
|
// make sure archives retain valid extensions
|
||||||
if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' ||
|
if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' ||
|
||||||
substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') {
|
substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') {
|
||||||
$relativeFilePath = preg_replace('/[0-9]*(\.tar\.[^.]+$)/', $i . '\\1', $relativeFilePath);
|
$relativeFilePath = preg_replace('/[0-9]*(\.tar\.[^.]+$)/', $i . '\\1', $relativeFilePath);
|
||||||
} else if (strpos($relativeFilePath, '.') !== false) {
|
} else if (strpos($relativeFilePath, '.') !== false) {
|
||||||
$relativeFilePath = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $relativeFilePath);
|
$relativeFilePath = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $relativeFilePath);
|
||||||
} else if (strpos($relativeFilePath, '_') !== false) {
|
} else if (strpos($relativeFilePath, '_') !== false) {
|
||||||
$relativeFilePath = preg_replace('/_([^_]+$)/', '_'.$i, $relativeFilePath);
|
$relativeFilePath = preg_replace('/_([^_]+$)/', '_'.$i, $relativeFilePath);
|
||||||
} else {
|
} else {
|
||||||
$relativeFilePath .= '_'.$i;
|
$relativeFilePath .= '_'.$i;
|
||||||
}
|
|
||||||
if($oldFilePath == $relativeFilePath && $i > 2) {
|
|
||||||
user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if($oldFilePath == $relativeFilePath && $i > 2) {
|
||||||
|
user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(file_exists($tmpFile['tmp_name']) && copy($tmpFile['tmp_name'], "$base/$relativeFilePath")) {
|
if(file_exists($tmpFile['tmp_name']) && copy($tmpFile['tmp_name'], "$base/$relativeFilePath")) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user