fixing oc-375 - a number is appended tp the filename
This commit is contained in:
parent
0b426b5e64
commit
a0d917fe98
|
@ -47,7 +47,8 @@ $result=array();
|
||||||
if(strpos($dir,'..') === false){
|
if(strpos($dir,'..') === false){
|
||||||
$fileCount=count($files['name']);
|
$fileCount=count($files['name']);
|
||||||
for($i=0;$i<$fileCount;$i++){
|
for($i=0;$i<$fileCount;$i++){
|
||||||
$target=stripslashes($dir) . $files['name'][$i];
|
// $target=stripslashes($dir) . $files['name'][$i];
|
||||||
|
$target = OC_Helper::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
|
||||||
if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){
|
if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i],$target)){
|
||||||
$meta=OC_FileCache::getCached($target);
|
$meta=OC_FileCache::getCached($target);
|
||||||
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>$files['name'][$i]);
|
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>$files['name'][$i]);
|
||||||
|
|
|
@ -492,4 +492,32 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a suffix to the name in case the file exists
|
||||||
|
*
|
||||||
|
* @param $path
|
||||||
|
* @param $filename
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function buildNotExistingFileName($path, $filename)
|
||||||
|
{
|
||||||
|
if ($pos = strrpos($filename, '.')) {
|
||||||
|
$name = substr($filename, 0, $pos);
|
||||||
|
$ext = substr($filename, $pos);
|
||||||
|
} else {
|
||||||
|
$name = $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newpath = $path . '/' . $filename;
|
||||||
|
$newname = $filename;
|
||||||
|
$counter = 2;
|
||||||
|
while (OC_Filesystem::file_exists($newpath)) {
|
||||||
|
$newname = $name . ' (' . $counter . ')' . $ext;
|
||||||
|
$newpath = $path . '/' . $newname;
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue