示例#1
0
文件: path.php 项目: vanie3/appland
 public static function setPermissions($path, $filemode = '0644', $foldermode = '0755')
 {
     // Initialise return value
     $ret = true;
     if (is_dir($path)) {
         $dh = opendir($path);
         while ($file = readdir($dh)) {
             if ($file != '.' && $file != '..') {
                 $fullpath = $path . '/' . $file;
                 if (is_dir($fullpath)) {
                     if (!MPath::setPermissions($fullpath, $filemode, $foldermode)) {
                         $ret = false;
                     }
                 } else {
                     if (isset($filemode)) {
                         if (!@chmod($fullpath, octdec($filemode))) {
                             $ret = false;
                         }
                     }
                 }
             }
         }
         closedir($dh);
         if (isset($foldermode)) {
             if (!@chmod($path, octdec($foldermode))) {
                 $ret = false;
             }
         }
     } else {
         if (isset($filemode)) {
             $ret = @chmod($path, octdec($filemode));
         }
     }
     return $ret;
 }
示例#2
0
 public static function setAllTempImageFolders($path = null)
 {
     if (!empty($path)) {
         $a = false;
         $arr = Yii::app()->params['storeImages'];
         foreach ($arr as $params => $value) {
             if ($params == $path) {
                 $a = true;
                 break;
             }
         }
         if ($a === true) {
             $param = Yii::app()->params['storeImages'][$path];
             if (isset($param) && !empty($param)) {
                 $tempdir = Yii::getPathOfAlias($param);
             }
         } else {
             echo 'error, wrong param';
             return false;
         }
     } else {
         $tempdir = Yii::getPathOfAlias(Yii::app()->params['storeImages']['thumbPath']);
     }
     MPath::setPermissions($tempdir, null, Yii::app()->params['storeImages']['dirMode']);
     // without octdec becose it will set in MPath
 }
示例#3
0
文件: file.php 项目: vanie3/appland
 public static function upload($src, $dest, $use_streams = false)
 {
     // Ensure that the path is valid and clean
     $dest = MPath::clean($dest);
     // Create the destination directory if it does not exist
     $baseDir = dirname($dest);
     if (!file_exists($baseDir)) {
         mimport('framework.filesystem.folder');
         MFolder::create($baseDir);
     }
     if ($use_streams) {
         $stream = MFactory::getStream();
         if (!$stream->upload($src, $dest)) {
             MError::raiseWarning(21, MText::sprintf('MLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()));
             return false;
         }
         return true;
     } else {
         // Initialise variables.
         $FTPOptions = MClientHelper::getCredentials('ftp');
         $ret = false;
         if ($FTPOptions['enabled'] == 1) {
             // Connect the FTP client
             mimport('framework.client.ftp');
             $ftp = MFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
             // Translate path for the FTP account
             $dest = MPath::clean(str_replace(MPATH_ROOT, $FTPOptions['root'], $dest), '/');
             // Copy the file to the destination directory
             if (is_uploaded_file($src) && $ftp->store($src, $dest)) {
                 unlink($src);
                 $ret = true;
             } else {
                 MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR02'));
             }
         } else {
             if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) {
                 // Short circuit to prevent file permission errors
                 if (MPath::setPermissions($dest)) {
                     $ret = true;
                 } else {
                     MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR01'));
                 }
             } else {
                 MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR02'));
             }
         }
         return $ret;
     }
 }