diff options
Diffstat (limited to 'apps/files/ajax/upload.php')
-rw-r--r-- | apps/files/ajax/upload.php | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 1d03cd89f83..0920bf62109 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -53,7 +53,7 @@ OCP\JSON::callCheck(); // get array with current storage stats (e.g. max file size) -$storageStats = \OCA\files\lib\Helper::buildFileStorageStatistics($dir); +$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); if (!isset($_FILES['files'])) { OCP\JSON::error(array('data' => array_merge(array('message' => $l->t('No file was uploaded. Unknown error')), $storageStats))); @@ -78,7 +78,7 @@ foreach ($_FILES['files']['error'] as $error) { } $files = $_FILES['files']; -$error = ''; +$error = false; $maxUploadFileSize = $storageStats['uploadMaxFilesize']; $maxHumanFileSize = OCP\Util::humanFileSize($maxUploadFileSize); @@ -98,33 +98,71 @@ $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\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, + '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'], ); } } } - OCP\JSON::encodedPrint($result); - exit(); } else { $error = $l->t('Invalid directory.'); } -OCP\JSON::error(array('data' => array_merge(array('message' => $error), $storageStats))); +if ($error === false) { + OCP\JSON::encodedPrint($result); + exit(); +} else { + OCP\JSON::error(array('data' => array_merge(array('message' => $error), $storageStats))); +} |