Skip to content

Commit

Permalink
Support custom permissions for folder and files
Browse files Browse the repository at this point in the history
  • Loading branch information
CauanCabral committed May 16, 2011
1 parent 83add90 commit 357603d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions models/behaviors/meio_upload.php
Expand Up @@ -33,8 +33,10 @@ class MeioUploadBehavior extends ModelBehavior {
'createDirectory' => true,
'encryptedFolder' => false,
'dir' => 'uploads{DS}{ModelName}{DS}{fieldName}',
'folderPermission' => 0755, // Set permission of dynamically created folder
'folderAsField' => null, // Can be the name of any field in $this->data
'uploadName' => null, // Can also be the tokens {ModelName} or {fieldName}
'filePermission' => 0755, // Set permission of uploaded files in the server
'removeOriginal' => false,
'maxSize' => 2097152, // 2MB
'allowedMime' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp', 'image/x-icon', 'image/vnd.microsoft.icon'),
Expand Down Expand Up @@ -449,7 +451,7 @@ function uploadCheckDir(&$model, $data) {
if (!is_dir($options['dir'])) {
if ($options['createDirectory']) {
$folder = &new Folder();
if (!$folder->create($options['dir'])) {
if (!$folder->create($options['dir'], $this->settings['folderPermission'])) {
trigger_error(sprintf(__d('meio_upload', 'MeioUploadBehavior Error: The directory %s does not exist and cannot be created.', true), $options['dir']), E_USER_WARNING);
return false;
}
Expand Down Expand Up @@ -1139,14 +1141,14 @@ function _createFolders($dir, $thumbDir, $thumbsizes) {
$folder = new Folder();

if (!$folder->cd($dir)) {
$folder->create($dir);
$folder->create($dir, $this->settings['folderPermission']);
}
if (!$folder->cd($dir. DS . $thumbDir)) {
$folder->create($dir . DS . $thumbDir);
$folder->create($dir . DS . $thumbDir, $this->settings['folderPermission']);
}
foreach ($thumbsizes as $thumbsize) {
if ($thumbsize != 'normal' && !$folder->cd($dir . DS . $thumbDir . DS . $thumbsize)) {
$folder->create($dir . DS . $thumbDir . DS . $thumbsize);
$folder->create($dir . DS . $thumbDir . DS . $thumbsize, $this->settings['folderPermission']);
}
}
}
Expand All @@ -1165,7 +1167,7 @@ function _copyFileFromTemp($tmpName, $saveAs) {
return false;
}
$file = new File($tmpName, $saveAs);
$temp = new File($saveAs, true);
$temp = new File($saveAs, true, $this->settings['filePermission']);
if (!$temp->write($file->read())) {
$results = __d('meio_upload', 'Problems in the copy of the file.', true);
}
Expand Down

0 comments on commit 357603d

Please sign in to comment.