本文整理汇总了PHP中FileUtil::mkdirs方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::mkdirs方法的具体用法?PHP FileUtil::mkdirs怎么用?PHP FileUtil::mkdirs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::mkdirs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createLocalDir
/**
* Create a directory below zikula's local cache directory.
*
* @param string $dir The name of the directory to create.
* @param mixed $mode The (UNIX) mode we wish to create the files with.
* @param bool $absolute Whether to process the passed dir as an absolute path or not.
*
* @return boolean true if successful, false otherwise.
*/
public static function createLocalDir($dir, $mode = 0777, $absolute = true)
{
$path = DataUtil::formatForOS(System::getVar('temp'), true) . '/' . $dir;
$mode = isset($mode) ? $mode : ServiceUtil::getManager()->getParameter('system.chmod_dir');
if (!FileUtil::mkdirs($path, $mode, $absolute)) {
return false;
}
return true;
}
示例2: createLocalDir
/**
* Create a directory below zikula's local cache directory.
*
* @param string $dir The name of the directory to create.
* @param mixed $mode The (UNIX) mode we wish to create the files with.
* @param bool $absolute Whether to process the passed dir as an absolute path or not.
*
* @return boolean true if successful, false otherwise.
*/
public static function createLocalDir($dir, $mode = null, $absolute = true)
{
$path = DataUtil::formatForOS(System::getVar('temp'), true) . '/' . $dir;
$mode = isset($mode) ? (int) $mode : System::getVar('system.chmod_dir');
if (!FileUtil::mkdirs($path, $mode, $absolute)) {
return false;
}
return true;
}
示例3: createLocalDir
/**
* Create a directory below zikula's local cache directory.
*
* @param string $dir The name of the directory to create.
* @param mixed $mode The (UNIX) mode we wish to create the files with.
* @param bool $absolute Whether to process the passed dir as an absolute path or not.
*
* @return boolean true if successful, false otherwise.
*/
public static function createLocalDir($dir, $mode = null, $absolute = true)
{
$sm = ServiceUtil::getManager();
$base = $sm['kernel.cache_dir'] . '/ztemp';
$path = $base . '/' . $dir;
$mode = isset($mode) ? (int) $mode : System::getVar('system.chmod_dir');
if (!FileUtil::mkdirs($path, $mode, $absolute)) {
return false;
}
return true;
}
示例4: update
/**
* Step 1 - Check if the needed files exists and if they are writeable
* @author Albert Pérez Monfort (aperezm@xtec.cat)
* @return if they exist and are writeable user can jump to step 2
*/
public function update()
{
$filesRealPath = FormUtil::getPassedValue('filesRealPath', isset($args['filesRealPath']) ? $args['filesRealPath'] : null, 'POST');
$usersFolder = FormUtil::getPassedValue('usersFolder', isset($args['usersFolder']) ? $args['usersFolder'] : null, 'POST');
if (!SecurityUtil::checkPermission('Files::', '::', ACCESS_ADMIN)) {
return LogUtil::registerPermissionError();
}
$multisites = false;
if (isset($GLOBALS['PNConfig']['Multisites']['multi']) && $GLOBALS['PNConfig']['Multisites']['multi'] == 1) {
// create the needed folders for the site
$siteDNS = isset($_GET['siteDNS']) ? DataUtil::formatForOS($_GET['siteDNS']) : null;
$filesRealPath = $GLOBALS['PNConfig']['Multisites']['filesRealPath'] . '/' . $siteDNS . $GLOBALS['PNConfig']['Multisites']['siteFilesFolder'];
if (!FileUtil::mkdirs($filesRealPath . '/' . $usersFolder, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $usersFolder);
return false;
}
$multisites = true;
}
// check if the needed files are located in the correct places and they are writeable
$file1 = false;
$file2 = false;
$fileWriteable1 = false;
$fileWriteable2 = false;
$path = $filesRealPath;
if (file_exists($path)) {
$file1 = true;
}
if (is_writeable($path)) {
$fileWriteable1 = true;
}
$path = $filesRealPath . '/' . $usersFolder;
if (file_exists($path)) {
$file2 = true;
}
if (is_writeable($path)) {
$fileWriteable2 = true;
}
if ($fileWriteable1 && $fileWriteable2) {
ModUtil::setVar('Files', 'folderPath', $filesRealPath);
ModUtil::setVar('Files', 'usersFolder', $usersFolder);
}
$this->view->assign('filesRealPath', $filesRealPath);
$this->view->assign('usersFolder', $usersFolder);
$this->view->assign('file1', $file1);
$this->view->assign('file2', $file2);
$this->view->assign('multisites', $multisites);
$this->view->assign('fileWriteable1', $fileWriteable1);
$this->view->assign('fileWriteable2', $fileWriteable2);
$this->view->assign('step', 'check');
return $this->view->fetch('Files_init.htm');
}
示例5: getNewFileReference
function getNewFileReference()
{
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$charLen = strlen($chars);
$id = $chars[mt_rand(0, $charLen - 1)] . $chars[mt_rand(0, $charLen - 1)];
$mediadir = $this->storageDir;
if (!file_exists($mediadir . '/' . $id)) {
FileUtil::mkdirs($mediadir . '/' . $id, 0777);
}
$id .= '/';
for ($i = 0; $i < 30; ++$i) {
$id .= $chars[mt_rand(0, $charLen - 1)];
}
return $id;
}
示例6: checkAndCreateUploadFolder
/**
* Creates upload folder including a subfolder for thumbnail and an .htaccess file within it.
*
* @param string $objectType Name of treated entity type.
* @param string $fieldName Name of upload field.
* @param string $allowedExtensions String with list of allowed file extensions (separated by ", ").
*
* @return Boolean whether everything went okay or not.
*/
protected function checkAndCreateUploadFolder($objectType, $fieldName, $allowedExtensions = '')
{
$uploadPath = $this->getFileBaseFolder($objectType, $fieldName, true);
// Check if directory exist and try to create it if needed
if (!is_dir($uploadPath) && !FileUtil::mkdirs($uploadPath, 0777)) {
LogUtil::registerStatus($this->__f('The upload directory "%s" does not exist and could not be created. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', array($uploadPath)));
return false;
}
// Check if directory is writable and change permissions if needed
if (!is_writable($uploadPath) && !chmod($uploadPath, 0777)) {
LogUtil::registerStatus($this->__f('Warning! The upload directory at "%s" exists but is not writable by the webserver.', array($uploadPath)));
return false;
}
// Write a htaccess file into the upload directory
$htaccessFilePath = $uploadPath . '/.htaccess';
$htaccessFileTemplate = 'modules/Reviews/docs/htaccessTemplate';
if (!file_exists($htaccessFilePath) && file_exists($htaccessFileTemplate)) {
$extensions = str_replace(',', '|', str_replace(' ', '', $allowedExtensions));
$htaccessContent = str_replace('__EXTENSIONS__', $extensions, FileUtil::readFile($htaccessFileTemplate));
if (!FileUtil::writeFile($htaccessFilePath, $htaccessContent)) {
LogUtil::registerStatus($this->__f('Warning! Could not write the .htaccess file at "%s".', array($htaccessFilePath)));
return false;
}
}
return true;
}
示例7: checkingModule
/**
* Check the configuration (and folder path)
* @author: Joan Guillén Pelegay
* @param:
* @return: array with check results
*/
public function checkingModule() {
// security check
if (!SecurityUtil::checkPermission('Files::', '::', ACCESS_ADD)) {
throw new Zikula_Exception_Forbidden();
}
// loading conf
$check = array();
$check['status'] = 'ok';
global $ZConfig;
// get folderPath
if (isset($ZConfig['Multisites']['multi']) && $ZConfig['Multisites']['multi'] == 1) {
$folderPath = $ZConfig['Multisites']['filesRealPath'] . '/' . $ZConfig['Multisites']['siteFilesFolder'];
$check['config'] = 'multisites';
} elseif (isset($ZConfig['FilesModule']['folderPath'])) {
$folderPath = $ZConfig['FilesModule']['folderPath'];
$check['config'] = 'config_site';
} else {
$folderPath = $ZConfig['System']['datadir'];
$check['config'] = 'default_site';
}
$check['folderPath'] = $folderPath;
// get usersFiles
if (!is_null(ModUtil::getVar('Files', 'usersFolder'))) {
$usersFiles = ModUtil::getVar('Files', 'usersFolder');
} else {
$usersFiles = 'usersFiles';
}
$check['usersFiles'] = $usersFiles;
// checking folderPath
if (file_exists($folderPath)) {
if (is_writeable($folderPath)){
if (!file_exists($folderPath . '/.htaccess')) {
FileUtil::writeFile($folderPath . '/.htaccess', $this->_HTACCESSCONTENT, true);
}
if (!file_exists($folderPath . '/.locked')) {
FileUtil::writeFile($folderPath . '/.locked', $this->_LOCKEDCONTENT, true);
}
$initFolderPath = $folderPath . '/' . $usersFiles;
if (!file_exists($initFolderPath)) {
if (!FileUtil::mkdirs($folderPath . '/' . $usersFiles, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $initFolderPath);
return false;
} else {
FileUtil::writeFile($initFolderPath . '/.htaccess', $this->_HTACCESSCONTENT, true);
FileUtil::writeFile($initFolderPath . '/.locked', $this->_LOCKEDCONTENT, true);
}
}
$initFolderPath .= '/' . strtolower(substr(UserUtil::getVar('uname'), 0, 1));
if (!file_exists($initFolderPath)) {
if (!FileUtil::mkdirs($initFolderPath, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $initFolderPath);
return false;
} else {
// create .htaccess and .locked files
FileUtil::writeFile($initFolderPath . '/.htaccess', $this->_HTACCESSCONTENT, true);
FileUtil::writeFile($initFolderPath . '/.locked', $this->_LOCKEDCONTENT, true);
}
}
$initFolderPath .= '/' . UserUtil::getVar('uname');
$defaultPublic = ModUtil::getVar('Files', 'defaultPublic');
if (!file_exists($initFolderPath)) {
if (!FileUtil::mkdirs($initFolderPath, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $initFolderPath);
return false;
} else {
// create .htaccess and .locked files
FileUtil::writeFile($initFolderPath . '/.htaccess', $this->_HTACCESSCONTENT, true);
if ($defaultPublic != '1'){
FileUtil::writeFile($initFolderPath . '/.locked', $this->_LOCKEDCONTENT, true);
}
}
// create user record in database
if (!ModUtil::apiFunc('Files', 'user', 'createUserFilesInfo')) {
LogUtil::registerError($this->__('User data creation error'));
return false;
}
}
// get user init folder
$check['initFolderPath'] = (SecurityUtil::checkPermission('Files::', "::", ACCESS_ADMIN)) ? $folderPath : $initFolderPath;
if (!file_exists($check['initFolderPath']) || !is_writable($check['initFolderPath'])) {
$errorMsg = $this->__f('The "%s" directory does not exist or is not writable.', $initFolderPath);
$this->view->assign('errorMsg', $errorMsg);
return $this->view->fetch('Files_user_errorMsg.tpl');
}
} else {
$check['status'] = 'ko';
$check['warning'] = "noWriteable_folderPath";
}
} else {
$check['status'] = 'ko';
$check['warning'] = "no_folderPath";
}
$check['agora'] = isset($ZConfig['iwmodules']['agora']) ? $ZConfig['iwmodules']['agora'] : false;
//.........这里部分代码省略.........
示例8: mkdir
/**
* Create a directory for news pics
* @param string $dir
*/
public static function mkdir($dir) {
$dom = ZLanguage::getModuleDomain('News');
if ($dir[0] == '/') {
LogUtil::registerError(__f("Warning! The image upload directory at [%s] appears to be 'above' the DOCUMENT_ROOT. Please choose a path relative to the webserver (e.g. images/news_picupload).", $dir, $dom));
} else {
if (is_dir($dir)) {
if (!is_writable($dir)) {
LogUtil::registerError(__f('Warning! The image upload directory at [%s] exists but is not writable by the webserver.', $dir, $dom));
}
} else {
// Try to create the specified directory
if (FileUtil::mkdirs($dir, 0777)) {
// write a htaccess file in the image upload directory
$htaccessContent = FileUtil::readFile('modules/News/docs/htaccess');
if (FileUtil::writeFile($dir . '/.htaccess', $htaccessContent)) {
LogUtil::registerStatus(__f('News publisher created the image upload directory successfully at [%s] and wrote an .htaccess file there for security.', $dir, $dom));
} else {
LogUtil::registerStatus(__f('News publisher created the image upload directory successfully at [%s], but could not write the .htaccess file there.', $dir, $dom));
}
} else {
LogUtil::registerStatus(__f('Warning! News publisher could not create the specified image upload directory [%s]. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', $dir, $dom));
}
}
}
}
示例9: setAsPublic
/**
* Set a folder as public or not public
* @author: Albert Pérez Monfort (aperezm@xtec.cat)
* @param: folder name
* @return: True if success or false in other case
*/
public function setAsPublic($args)
{
// get parameters from whatever input we need.
$folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'GET');
$folder = str_replace("|", "/", $folder);
$not = FormUtil::getPassedValue('not', isset($args['not']) ? $args['not'] : null, 'GET');
$external = FormUtil::getPassedValue('external', isset($args['external']) ? $args['external'] : null, 'GET');
$hook = FormUtil::getPassedValue('hook', isset($args['hook']) ? $args['hook'] : null, 'GET');
// security check
if (!SecurityUtil::checkPermission('Files::', "::", ACCESS_ADD)) {
return LogUtil::registerError($this->__('Error! You are not authorized to access this module.'), 403);
}
// protection. User can not navigate out their root folder
if ($folder == ".." || $folder == "." || strpos($folder, "..") !== false) {
$errorMsg = $this->__('Invalid folder') . ': ' . $folder;
$this->view->assign('errorMsg', $errorMsg);
return $this->view->fetch('Files_user_errorMsg.tpl');
}
$returnType = $external == 1 ? 'external' : 'user';
$returnFunc = $external == 1 ? 'getFiles' : 'main';
if ($not == null) {
$url = $initFolderPath = ModUtil::func('Files', 'user', 'getInitFolderPath') . '/' . $folder;
// if the folder .tbn for thumbnails does not exists create it
if (!file_exists($url . '/.tbn')) {
if (FileUtil::mkdirs($url . '/.tbn', 0777, true)) {
// create protection files
ModUtil::func('Files', 'user', 'createaccessfile', array('folder' => $folder . '/.tbn', 'onlyHtaccess' => 1));
}
}
// delete protection file
$whereToDelete = $url . '/.locked';
if (file_exists($whereToDelete)) {
unlink($whereToDelete);
}
$whereToDelete = $url . '/.tbn/.locked';
if (file_exists($whereToDelete)) {
unlink($whereToDelete);
}
} else {
// create protection files
if (ModUtil::func('Files', 'user', 'createaccessfile', array('folder' => $folder))) {
ModUtil::func('Files', 'user', 'createaccessfile', array('folder' => $folder . '/.tbn'));
}
}
$folder = str_replace("/", "|", $folder);
return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder, 'hook' => $hook)));
}