From d487a424565bd26406f9f747ea9bc578b4a524a4 Mon Sep 17 00:00:00 2001 From: "Nathan J. Brauer" Date: Wed, 19 Dec 2012 17:52:44 -0800 Subject: [PATCH] API Default to Upload::$uploads_dir in UploadField --- forms/FileField.php | 8 ++++---- forms/UploadField.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/forms/FileField.php b/forms/FileField.php index 95ffc1d98..f8a9d6b8c 100644 --- a/forms/FileField.php +++ b/forms/FileField.php @@ -64,11 +64,11 @@ class FileField extends FormField { /** * Partial filesystem path relative to /assets directory. - * Defaults to 'Uploads'. + * Defaults to Upload::$uploads_folder. * * @var string */ - protected $folderName = 'Uploads'; + protected $folderName = false; /** * Create a new file field. @@ -111,7 +111,7 @@ class FileField extends FormField { $file = new $fileClass(); } - $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->folderName); + $this->upload->loadIntoFile($_FILES[$this->name], $file, $this->getFolderName()); if($this->upload->isError()) return false; $file = $this->upload->getFile(); @@ -160,7 +160,7 @@ class FileField extends FormField { * @return string */ public function getFolderName() { - return $this->folderName; + return ($this->folderName !== false) ? $this->folderName : Upload::$uploads_folder; } public function validate($validator) { diff --git a/forms/UploadField.php b/forms/UploadField.php index 033d2f956..272e9ce5b 100644 --- a/forms/UploadField.php +++ b/forms/UploadField.php @@ -431,7 +431,7 @@ class UploadField extends FileField { * @return UploadField_ItemHandler */ public function handleSelect(SS_HTTPRequest $request) { - return UploadField_SelectHandler::create($this, $this->folderName); + return UploadField_SelectHandler::create($this, $this->getFolderName()); } /** @@ -500,7 +500,7 @@ class UploadField extends FileField { // Get the uploaded file into a new file object. try { - $this->upload->loadIntoFile($tmpfile, $fileObject, $this->folderName); + $this->upload->loadIntoFile($tmpfile, $fileObject, $this->getFolderName()); } catch (Exception $e) { // we shouldn't get an error here, but just in case $return['error'] = $e->getMessage();