From: Jörn Friedrich Dreyer Date: Thu, 19 Sep 2013 15:00:54 +0000 (+0200) Subject: Merge branch 'master' into fix_3728_with_file_exists_dialog X-Git-Tag: v6.0.0alpha2~159^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e0631b3b81a5669620122964d0326ead187de30;p=nextcloud-server.git Merge branch 'master' into fix_3728_with_file_exists_dialog Conflicts: apps/files/js/filelist.js --- 7e0631b3b81a5669620122964d0326ead187de30 diff --cc apps/files/ajax/upload.php index 12724c0c5bc,41d3a3eca4f..3d5314afc89 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@@ -98,58 -98,26 +98,60 @@@ $result = array() 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'], ); } } diff --cc apps/files/js/filelist.js index 39df91c94b4,fe706801b9e..4fc1b95a0ab --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@@ -762,21 -744,11 +792,28 @@@ $(document).ready(function() 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+')'); + }); } } });