本文整理汇总了PHP中FileUtil::writeFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::writeFile方法的具体用法?PHP FileUtil::writeFile怎么用?PHP FileUtil::writeFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::writeFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
public function install()
{
if (!SecurityUtil::checkPermission('Files::', '::', ACCESS_ADMIN)) {
return LogUtil::registerPermissionError();
}
// set content of the files .htaccess and .locked
$htaccessContent = "# Avoid direct web access to folder files\r\nOrder deny,allow\r\nDeny from all\r\n";
$lockedContent = "# Avoid direct web access with the file file.php\r\n";
// Create module table
if (!DBUtil::createTable('Files')) {
return false;
}
//Create indexes
$pntable = DBUtil::getTables();
$c = $pntable['Files_column'];
DBUtil::createIndex($c['userId'], 'Files', 'userId');
// create security files
FileUtil::writeFile(ModUtil::getVar('Files', 'folderPath') . '/.htaccess', $htaccessContent, true);
FileUtil::writeFile(ModUtil::getVar('Files', 'folderPath') . '/.locked', $lockedContent, true);
FileUtil::writeFile(ModUtil::getVar('Files', 'folderPath') . '/' . ModUtil::getVar('Files', 'usersFolder') . '/.htaccess', $htaccessContent, true);
FileUtil::writeFile(ModUtil::getVar('Files', 'folderPath') . '/' . ModUtil::getVar('Files', 'usersFolder') . '/.locked', $lockedContent, true);
//Create module vars
ModUtil::setVar('Files', 'showHideFiles', '0');
ModUtil::setVar('Files', 'allowedExtensions', 'gif,png,jpg,odt,doc,pdf,zip');
ModUtil::setVar('Files', 'defaultQuota', 1);
ModUtil::setVar('Files', 'groupsQuota', 's:0:"";');
ModUtil::setVar('Files', 'filesMaxSize', '1000000');
ModUtil::setVar('Files', 'maxWidth', '250');
ModUtil::setVar('Files', 'maxHeight', '250');
ModUtil::setVar('Files', 'editableExtensions', 'php,htm,html,htaccess,css,js,tpl');
// Set up module hook
ModUtil::registerHook('item', 'display', 'GUI', 'Files', 'user', 'Files');
return true;
}
示例2: processRecoveryTempdir
public function processRecoveryTempdir()
{
// some checks
if (!isset($this->tempdir)) {
$this->setError(__('Temporary directory is not set'));
return false;
}
if (empty($this->tempdir)) {
$this->setError(__('Temporary directory cannot be empty'));
return false;
}
$dir_errors = array();
// recreate only the subdirectories that are missing
if ($this->tempdirexists) {
foreach ($this->tempdirsubs as $dir => $status) {
if ($status == 0) {
$result = mkdir($this->tempdir . '/' . $dir, null, true);
if ($result == false) {
array_push($dir_errors, $dir);
}
}
}
} else {
foreach ($this->tempdirsubs as $dir => $status) {
$result = mkdir($this->tempdir . '/' . $dir, null, true);
if ($result == false) {
array_push($dir_errors, $dir);
}
}
}
if (count($dir_errors) > 0) {
$this->setError(__f('Error creating temp subdirectories [%s]', implode(",", $dir_errors)));
return false;
}
// create htaccess only if needed
if (!$this->tempdirexists) {
$htaccess_file = 'SetEnvIf Request_URI "\\.css$" object_is_css=css' . "\n";
$htaccess_file .= 'SetEnvIf Request_URI "\\.js$" object_is_js=js' . "\n";
$htaccess_file .= 'Order deny,allow' . "\n";
$htaccess_file .= 'Deny from all' . "\n";
$htaccess_file .= 'Allow from env=object_is_css' . "\n";
$htaccess_file .= 'Allow from env=object_is_js' . "\n";
$result = FileUtil::writeFile($this->tempdir . '/.htaccess', $htaccess_file);
if ($result === false) {
$this->setError(__f('There was a problem creating .htaccess file. You will have to download it yourself from the <a href="%s">CoZi</a> and place it inside your temp directory', 'https://code.zikula.org/svn/core/branches/zikula-1.3/src/ztemp/.htaccess'));
return false;
}
}
// Set a status message.
$this->setStatus(__('The temp directory was successfully rebuilt'));
// Recovery successful.
return true;
}
示例3: 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;
}
示例4: 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;
//.........这里部分代码省略.........
示例5: 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));
}
}
}
}
示例6: getInitFolderPath
/**
* Get the init folder path. For a multisites installation the folder path depends on the siteDNS.
* For a not multiple installation the folder path is stored in a module variable.
* @author Albert Pérez Monfort
* @return The initial folder path
*/
public function getInitFolderPath()
{
// security check
if (!SecurityUtil::checkPermission('Files::', "::", ACCESS_ADD) || !UserUtil::isLoggedIn()) {
return LogUtil::registerError($this->__('Error! You are not authorized to access this module.'), 403);
}
if (isset($GLOBALS['PNConfig']['Multisites']['multi']) && $GLOBALS['PNConfig']['Multisites']['multi'] == 1) {
$siteDNS = FormUtil::getPassedValue('siteDNS', '', 'GET');
// if siteDNS is the main site the root is the initial folder. If not it is the initial folder by the site
$rootFolderPath = $siteDNS == $GLOBALS['PNConfig']['Multisites']['mainSiteURL'] ? $GLOBALS['PNConfig']['Multisites']['filesRealPath'] : $GLOBALS['PNConfig']['Multisites']['filesRealPath'] . '/' . $siteDNS . $GLOBALS['PNConfig']['Multisites']['siteFilesFolder'];
} else {
$rootFolderPath = ModUtil::getVar('Files', 'folderPath');
}
// checks if $rootFolderPath exists. If not user is send to error page
if (!file_exists($rootFolderPath)) {
$errorMsg = $this->__f('The folder <strong>%s</strong> has not been found.', $rootFolderPath);
$this->view->assign('errorMsg', $errorMsg);
return $this->view->fetch('Files_user_errorMsg.tpl');
}
// checks if users folder exists. If user is admimistrator return initial folder otherwise return an error page
$userFolder = $rootFolderPath . '/' . ModUtil::getVar('Files', 'usersFolder');
if (!file_exists($userFolder)) {
if (SecurityUtil::checkPermission('Files::', "::", ACCESS_ADMIN)) {
return $rootFolderPath;
} else {
$errorMsg = $this->__('Directory creation error. Please contact with the administrator') . ': ' . $folderName;
$this->view->assign('errorMsg', $errorMsg);
return $this->view->fetch('Files_user_errorMsg.tpl');
}
}
// get user folder path depending on user name and if it not exists, create it
$userFolder = ModUtil::getVar('Files', 'usersFolder') . '/' . strtolower(substr(UserUtil::getVar('uname'), 0, 1));
if (!file_exists($rootFolderPath . '/' . $userFolder)) {
if (!FileUtil::mkdirs($rootFolderPath . '/' . $userFolder, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $rootFolderPath . '/' . $userFolder);
return false;
}
// create .htaccess and .locked files
FileUtil::writeFile($rootFolderPath . '/' . $userFolder . '/.htaccess', $this->_HTACCESSCONTENT, true);
FileUtil::writeFile($rootFolderPath . '/' . $userFolder . '/.locked', $this->_LOCKEDCONTENT, true);
}
$userFolder .= '/' . UserUtil::getVar('uname');
if (!file_exists($rootFolderPath . '/' . $userFolder)) {
// create user record in database
if ($created = ModUtil::apiFunc('Files', 'user', 'createUserFilesInfo')) {
// create dir
if (!FileUtil::mkdirs($rootFolderPath . '/' . $userFolder, 0777, true)) {
LogUtil::registerError($this->__('Directory creation error') . ': ' . $rootFolderPath . '/' . $userFolder);
return false;
}
// create .htaccess and .locked files
ModUtil::func('Files', 'user', 'createaccessfile', array('folder' => $userFolder));
}
}
// get user init folder
$initFolderPath = SecurityUtil::checkPermission('Files::', "::", ACCESS_ADMIN) ? $rootFolderPath : $rootFolderPath . '/' . $userFolder;
if (!file_exists($initFolderPath) || !is_writable($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');
}
return $initFolderPath;
}