if (strpos($dir, '..') === false) {
$fileCount = count($files['name']);
for ($i = 0; $i < $fileCount; $i++) {
- $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
- $target = \OC\Files\Filesystem::normalizePath($target);
- if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
+ if (isset($_POST['resolution']) && $_POST['resolution']==='autorename') {
+ // append a number in brackets like 'filename (2).ext'
+ $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
+ } else {
+ $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]);
+ }
+
+ if ( ! \OC\Files\Filesystem::file_exists($target)
+ || (isset($_POST['resolution']) && $_POST['resolution']==='replace')
+ ) {
+ // upload and overwrite file
+ if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
+
+ // updated max file size after upload
+ $storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir);
+
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
+ if ($meta === false) {
+ $error = $l->t('Upload failed. Could not get file info.');
+ } else {
+ $result[] = array('status' => 'success',
+ 'mime' => $meta['mimetype'],
+ 'mtime' => $meta['mtime'],
+ 'size' => $meta['size'],
+ 'id' => $meta['fileid'],
+ 'name' => basename($target),
+ 'originalname' => $files['tmp_name'][$i],
+ 'uploadMaxFilesize' => $maxUploadFileSize,
- 'maxHumanFilesize' => $maxHumanFileSize
++ 'maxHumanFilesize' => $maxHumanFileSize,
++ 'permissions' => $meta['permissions'],
+ );
+ }
+
+ } else {
+ $error = $l->t('Upload failed. Could not find uploaded file');
+ }
+
+ } else {
+ // file already exists
$meta = \OC\Files\Filesystem::getFileInfo($target);
- // updated max file size after upload
- $storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir);
if ($meta === false) {
- OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('Upload failed')), $storageStats)));
- exit();
+ $error = $l->t('Upload failed. Could not get file info.');
} else {
- $result[] = array('status' => 'success',
+ $result[] = array('status' => 'existserror',
'mime' => $meta['mimetype'],
+ 'mtime' => $meta['mtime'],
'size' => $meta['size'],
'id' => $meta['fileid'],
'name' => basename($target),
- 'originalname' => $files['name'][$i],
+ 'originalname' => $files['tmp_name'][$i],
'uploadMaxFilesize' => $maxUploadFileSize,
- 'maxHumanFilesize' => $maxHumanFileSize
+ 'maxHumanFilesize' => $maxHumanFileSize,
+ 'permissions' => $meta['permissions'],
);
}
}
var date=new Date();
var param = {};
if ($('#publicUploadRequestToken').length) {
- param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + uniqueName;
+ param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
}
+ //should the file exist in the list remove it
+ FileList.remove(file.name);
+
// create new file context
- data.context = FileList.addFile(uniqueName,size,date,true,false,param);
+ data.context = FileList.addFile(file.name, file.size, date, false, false, param);
+
+ // update file data
+ data.context.attr('data-mime',file.mime).attr('data-id',file.id);
+
++ var permissions = data.context.data('permissions');
++ if(permissions != file.permissions) {
++ data.context.attr('data-permissions', file.permissions);
++ data.context.data('permissions', file.permissions);
++ }
++ FileActions.display(data.context.find('td.filename'));
+
+ var path = getPathForPreview(file.name);
+ lazyLoadPreview(path, file.mime, function(previewpath){
+ data.context.find('td.filename').attr('style','background-image:url('+previewpath+')');
+ });
}
}
});