create a new filename when the uploaded file already exist
This commit is contained in:
parent
74ba09f95c
commit
8ecddb5bc3
|
@ -47,11 +47,10 @@ $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 = OC_Helper::buildNotExistingFileName(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'=>basename($target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OC_JSON::encodedPrint($result);
|
OC_JSON::encodedPrint($result);
|
||||||
|
|
|
@ -211,12 +211,12 @@ $(document).ready(function() {
|
||||||
var size=t('files','Pending');
|
var size=t('files','Pending');
|
||||||
}
|
}
|
||||||
if(files){
|
if(files){
|
||||||
FileList.addFile(files[i].name,size,date,true);
|
FileList.addFile(getUniqueName(files[i].name),size,date,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
var filename=this.value.split('\\').pop(); //ie prepends C:\fakepath\ in front of the filename
|
var filename=this.value.split('\\').pop(); //ie prepends C:\fakepath\ in front of the filename
|
||||||
FileList.addFile(filename,'Pending',date,true);
|
FileList.addFile(getUniqueName(filename),'Pending',date,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading
|
//clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading
|
||||||
|
@ -570,3 +570,22 @@ function getMimeIcon(mime, ready){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getMimeIcon.cache={};
|
getMimeIcon.cache={};
|
||||||
|
|
||||||
|
function getUniqueName(name){
|
||||||
|
if($('tr').filterAttr('data-file',name).length>0){
|
||||||
|
var parts=name.split('.');
|
||||||
|
var extension=parts.pop();
|
||||||
|
var base=parts.join('.');
|
||||||
|
numMatch=base.match(/\((\d+)\)/);
|
||||||
|
var num=2;
|
||||||
|
if(numMatch && numMatch.length>0){
|
||||||
|
num=parseInt(numMatch[numMatch.length-1])+1;
|
||||||
|
base=base.split('(')
|
||||||
|
base.pop();
|
||||||
|
base=base.join('(').trim();
|
||||||
|
}
|
||||||
|
name=base+' ('+num+').'+extension;
|
||||||
|
return getUniqueName(name);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue