Permalink
Browse files

deleteAll() to support object delete

  • Loading branch information...
1 parent f6ac5a1 commit 1813e143b5a50055eb7cd8b400578b76221c7d17 root committed Jul 16, 2012
Showing with 43 additions and 1 deletion.
  1. +33 −0 Controller/Component/UploadComponent.php
  2. 0 Controller/Component/empty
  3. +9 −0 README.md
  4. +1 −1 webroot/js/fileuploader.js
@@ -0,0 +1,33 @@
+<?php
+/**
+ *
+ * Dual-licensed under the GNU GPL v3 and the MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2012, Suman (srs81 @ GitHub)
+ * @package plugin
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ * and/or GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
+ */
+
+class UploadComponent extends Component {
+
+ public function deleteAll ($model, $id) {
+ require_once (ROOT . DS . APP_DIR . "/Plugin/AjaxMultiUpload/Config/bootstrap.php");
+ $dir = Configure::read('AMU.directory');
+ if (strlen($dir) < 1) $dir = "files";
+
+ $lastDir = $this->last_dir ($model, $id);
+ $dirPath = WWW_ROOT . DS . $dir . DS . $lastDir . DS;
+ $files = glob($dirPath . '*', GLOB_MARK);
+ foreach ($files as $file) {
+ unlink($file);
+ }
+ rmdir($dirPath);
+ }
+
+ // The "last mile" of the directory path for where the files get uploaded
+ function last_dir ($model, $id) {
+ return $model . "/" . $id;
+ }
+}
No changes.
View
@@ -60,6 +60,7 @@ in just your specific controller where you will use it as below:
```php
var $helpers = array('AjaxMultiUpload.Upload');
+var $components = array('AjaxMultiUpload.Upload');
```
### Add to views
@@ -78,6 +79,14 @@ and this to your View/Companies/edit.ctp:
echo $this->Upload->edit('Company', $this->Form->fields['Company.id']);
```
+### Add to controllers
+
+Add the following to the delete() function of your Company controller where appropriate (either first line, or right after $this->Company->delete() check):
+
+```php
+echo $this->Upload->deleteAll('Company', $id);
+```
+
## Some Gotchas
Thanks to rscherf@github for the following two fixes.
@@ -1244,4 +1244,4 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
this._xhrs[id] = null;
}
}
-});
+});

0 comments on commit 1813e14

Please sign in to comment.