commit ef2b735cdd88595bde339efa72c0487f0d0499d9
parent 57898d04ab95c4feebe0dee18073f738e3bbb8d9
Author: Felicitus <felicitus@felicitus.org>
Date: Mon, 12 Mar 2012 03:28:53 +0100
Check permissions when uploading, fixes #106
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php b/src/backend/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php
@@ -1,5 +1,7 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\UploadedFile;
+use de\RaumZeitLabor\PartKeepr\Util\SerializableException;
+
use de\RaumZeitLabor\PartKeepr\Util\BaseEntity;
declare(encoding = 'UTF-8');
@@ -95,6 +97,8 @@ abstract class UploadedFile extends BaseEntity {
$this->size = filesize($path);
$this->ensureFilePathExists();
+ $this->checkPermissions();
+
copy($path, $this->getFilename());
$this->setOriginalFilename(basename($path));
@@ -272,4 +276,15 @@ abstract class UploadedFile extends BaseEntity {
}
}
+ /**
+ * Checks if the path where the file should be stored has sufficient permissions to do so.
+ *
+ * @throws SerializableException
+ */
+ public function checkPermissions () {
+ if (!is_writable($this->getFilePath())) {
+ throw new SerializableException(
+ sprintf(PartKeepr::i18n("Unable to write to directory %s"), $this->getFilePath()));
+ }
+ }
}
diff --git a/src/frontend/js/Dialogs/FileUploadDialog.js b/src/frontend/js/Dialogs/FileUploadDialog.js
@@ -45,6 +45,14 @@ Ext.define('PartKeepr.FileUploadDialog', {
this.close();
},this),
failure: function(form, action) {
+
+ var data = Ext.decode(action.response.responseText);
+
+ request = {
+ response: action.response.responseText
+ };
+
+ PartKeepr.ExceptionWindow.showException(data.exception, request);
}
});
}