Skip to content

Commit

Permalink
[Document Repository] Fix duplicate filename in path (aces#4466)
Browse files Browse the repository at this point in the history
Got rid of $fullPath usage. Code was checking for a directory named by the file, creating a directory named after the file, and uploading the file inside this new directory.
  • Loading branch information
Jkat authored and nicolasbrossard committed Jun 26, 2019
1 parent 92d60fa commit 6cc6051
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/document_repository/php/files.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ class Files extends \NDB_Page
);
break;
case "GET":
$record = basename($request->getUri()->getPath());
$name = \User::singleton()->getUsername();
$record = urldecode(basename($request->getUri()->getPath()));
if (!is_numeric($record)) {
$file = __DIR__ . "/../user_uploads/$record";
$file = __DIR__ . "/../user_uploads/$name/$record";
return (new \LORIS\Http\Response())
->withHeader(
'Content-Disposition',
Expand Down Expand Up @@ -372,15 +373,15 @@ class Files extends \NDB_Page
$fileSize = $uploadedFile->getSize();
$fileName = $uploadedFile->getClientFileName();
$fileType = pathinfo($fileName, PATHINFO_EXTENSION);
$uploadPath = "$base/modules/document_repository/user_uploads/";
$uploadPath = "$base/modules/document_repository/user_uploads/$name/";
// $category is a string representation of an ID, and so should be at
// least equal to zero.
if (intval($category) < 0) {
throw new \LorisException(
"'Category' parameter must be a positive integer."
);
}
// Check to see if $fullPath is writable. If not, throw an error. If it
// Check to see if $uploadPath is writable. If not, throw an error. If it
// doesn't exist, create an uploads folder for the logged-in user.
if (!is_writable($uploadPath)) {
if (file_exists($uploadPath)) {
Expand Down

0 comments on commit 6cc6051

Please sign in to comment.