Skip to content

Commit

Permalink
Accepted files parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
telerim committed Jul 22, 2015
1 parent 6408775 commit eca83f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -114,12 +114,12 @@ echo $this->Upload->deleteAll('Company', $id);

### Restrict file types to upload

Just before adding the line to allow upload (this->Upload->Edit), add this to restrict to only the types and/or extensions you want:
Add a third parameter to the this->Upload->edit() function, which specifies which types you want to restrict the upload to.
```php
echo $this->Upload->setAcceptedFiles("audio/*,image/*,.psd,.pdf");
echo $this->Upload->edit('Company', $this->Form->fields['Company.id'], "audio/*,image/*,.psd,.pdf");
```

If you don't specify this line, users will be able to upload all file types (so all files types are allowed by default.)
If you don't specify the third parameter, users will be able to upload all file types (so all files types are allowed by default.)

Documentation on the string to use to specify files / types to upload is in this Stackoverflow answer about Dropzone allowed types: http://stackoverflow.com/a/17275873

Expand Down
12 changes: 2 additions & 10 deletions View/Helper/UploadHelper.php
Expand Up @@ -12,8 +12,6 @@

class UploadHelper extends AppHelper {

$acceptedFiles = "";

public function view ($model, $id, $edit=false) {
$results = $this->listing ($model, $id);

Expand Down Expand Up @@ -66,7 +64,7 @@ public function listing ($model, $id) {
return array("baseUrl" => $baseUrl, "directory" => $directory, "files" => $files);
}

public function edit ($model, $id) {
public function edit ($model, $id, $acceptedFiles=null) {
$dir = Configure::read('AMU.directory');
if ($dir === "") $dir = "files";
$size = Configure::read ('AMU.filesizeMB');
Expand All @@ -76,7 +74,7 @@ public function edit ($model, $id) {
$webroot = Router::url("/") . "ajax_multi_upload";
// Replace / with underscores for Ajax controller
$lastDir = str_replace ("/", "___", $this->last_dir ($model, $id));
if ($acceptedFiles === "") {
if ($acceptedFiles == null) {
$acceptedFilesStr = "";
} else {
$acceptedFilesStr = "acceptedFiles: \"$acceptedFiles\"";
Expand All @@ -95,12 +93,6 @@ public function edit ($model, $id) {
return $str;
}

// Set accepted files for Dropzone
// Documentation: http://stackoverflow.com/a/17275873
public function setAcceptedFiles($fileList) {
$acceptedFiles = $fileList;
}

// The "last mile" of the directory path for where the files get uploaded
public function last_dir ($model, $id) {
return $model . "/" . $id;
Expand Down

0 comments on commit eca83f2

Please sign in to comment.