BUG Fixing non-object on file upload

Upload::load() assumes that a parent Folder always exists for a file
upload, but that's not always the case, and a non-object error is
given if no parent folder.

Check the folder exists first before getting the ID.
This commit is contained in:
Sean Harvey 2012-11-08 21:28:05 +13:00
parent edb4ecd4d9
commit 68826357cc

View File

@ -159,7 +159,7 @@ class Upload extends Controller {
}
if(file_exists($tmpFile['tmp_name']) && copy($tmpFile['tmp_name'], "$base/$relativeFilePath")) {
$this->file->ParentID = $parentFolder->ID;
$this->file->ParentID = $parentFolder ? $parentFolder->ID : 0;
// This is to prevent it from trying to rename the file
$this->file->Name = basename($relativeFilePath);
$this->file->write();