本文整理汇总了PHP中dir::create方法的典型用法代码示例。如果您正苦于以下问题:PHP dir::create方法的具体用法?PHP dir::create怎么用?PHP dir::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dir
的用法示例。
在下文中一共展示了dir::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public static function create($dir, $mode = 0755)
{
if (is_dir($dir) || @mkdir($dir, $mode)) {
return true;
}
if (!dir::create(dirname($dir), $mode)) {
return false;
}
return @mkdir($dir, $mode);
}
示例2: createDir
/**
* 创建目录
* @staticvar array $dirArr
* @param type $dir
* @return boolean
*/
private function createDir($dir)
{
static $dirArr = array();
if (isset($dirArr[$dir])) {
return true;
}
if (!dir::create($dir)) {
return false;
}
$dirArr[$dir] = true;
return true;
}
示例3: run
public function run()
{
if (C("SESSION_SAVE_PATH")) {
session_save_path(C("SESSION_SAVE_PATH"));
}
if (!session_save_path()) {
dir::create(ROOT_PATH . '/session');
session_save_path(ROOT_PATH . '/session');
}
session_name(C("SESSION_NAME"));
session_set_save_handler(array(&$this, "open"), array(&$this, "close"), array(&$this, "read"), array(&$this, "write"), array(&$this, "destroy"), array(&$this, "gc"));
}
示例4: set
/**
* 设置缓存数据
* @param type $args
* @return type
*/
public function set($name, $data, $time = null, $path = null)
{
$cacheFile = $this->getCacheFile($name, $path);
if ($this->isValid($name, $time, $path)) {
//缓存是否有效
return true;
}
$data = "<?php \r\n if(!defined('PATH_HD'))exit;\r\n" . $this->createCatchData($name, $data) . "?>";
dir::create(dirname($cacheFile));
//创建缓存目录
if (file_put_contents($cacheFile, $data)) {
return true;
}
}
示例5: display
/**
* 模板显示
* @param string $tpl_file 模板文件
* @param number $cacheTime 缓存时间
* @param string $contentType 文件类型
* @param string $charset 字符集
* @param boolean $show 是否显示
*/
public function display($tplFile = "", $cacheTime = null, $contentType = "text/html", $charset = "", $show = true)
{
$this->endFix = '.' . trim(C("TPL_FIX"), '.');
$this->tplFile = $this->getTemplateFile($tplFile);
$this->set_cache_file();
//设置缓存文件
$this->set_cache_time($cacheTime);
//设置缓存时间
$this->compileFile = CACHE_COMPILE_PATH . '/' . md5_d($this->tplFile) . '.php';
if (C("debug")) {
tplCompile(array(basename($this->tplFile), $this->compileFile));
//记录模板编译文件
}
$content = false;
//静态缓存数据内容
if ($this->cacheTime > 0) {
//缓存控制ssp
dir::create(CACHE_TPL_PATH);
//缓存目录
if ($this->cacheStat || $this->is_cache($this->cacheTime)) {
$content = file_get_contents($this->cacheFile);
}
}
if ($content === false) {
//不使用缓存
if ($this->checkCompile($tplFile)) {
//编译文件失效
$this->compile();
}
$_CONFIG = C();
$_LANGUAGE = L();
if (!empty(self::$vars)) {
//加载全局变量
extract(self::$vars);
}
ob_start();
include $this->compileFile;
$content = ob_get_clean();
if ($this->cacheTime > 0) {
file_put_contents($this->cacheFile, $content);
}
}
if ($show) {
$charset = strtoupper(C("CHARSET")) == 'UTF8' ? "UTF-8" : strtoupper(C("CHARSET"));
header("Content-type:" . $contentType . ';charset=' . $charset);
echo $content;
} else {
return $content;
}
}
示例6: run
public function run()
{
$this->content = file_get_contents($this->tplFile);
//获得模板内容
$this->replaceAssignVar();
$this->loadParseTags();
//加载标签库 及解析标签
$this->compile();
//解析全局内容
$this->replaceConst();
//将所有常量替换 如把__APP__进行替换
$this->content = '<?php if(!defined("PATH_HD"))exit;?>' . "\r\n" . $this->content;
if (!is_dir(CACHE_COMPILE_PATH)) {
dir::create(CACHE_COMPILE_PATH);
}
file_put_contents($this->compileFile, $this->content);
}
示例7: write
public static function write($message, $type = 3, $destination = NULL, $extra_headers = NULL)
{
if (!C("LOG_START")) {
return;
}
dir::create(PATH_LOG);
if (is_null($destination)) {
$destination = PATH_LOG . '/' . date("ymd") . md5(C("LOG_KEY")) . ".log";
}
if ($type == 3) {
if (is_file($destination) && filesize($destination) > C("LOG_SIZE")) {
rename($destination, dirname($destination) . "/" . time() . ".log");
}
}
$now = date("y-m-d h:i:s");
$message = $message . "\t[时间]" . $now . "\r\n";
error_log($message, $type, $destination, $extra_headers = null);
}
示例8: _getLinkageCache
/**
* 取得联动分类或城市的缓存数据值
* @param string $type city or linkage
* @return 换成数据数组
*/
private function _getLinkageCache($type = 'linkage')
{
$field = array('laid', 'title');
if ($type == 'city') {
$field = array('id', 'name');
}
$cache = array();
$path = PATH_ROOT . '/caches/linkage';
$file = $path . '/' . $type . '.php';
if (file_exists($file)) {
$cache = (include $file);
} else {
dir::create($path);
$db = M($type);
$linkages = $db->field(implode(',', $field))->findall();
foreach ($linkages as $value) {
$cache[$value[$field[0]]] = $value[$field[1]];
}
file_put_contents($file, '<?php if(!defined("PATH_HD")){exit;}return ' . var_export($cache, TRUE) . ';');
}
return $cache;
}
示例9: add
public function add()
{
if (IS_POST) {
$data = $_POST;
$data['has_adminlist'] = isset($_POST['has_adminlist']) ? 1 : 0;
//有后台
$data['has_outurl'] = isset($_POST['has_outurl']) ? 1 : 0;
//前台访问
$data['config'] = isset($_POST['config']) ? 1 : 0;
//有配置文件
//-------------------检查必要信息
$this->db->validate = array(array('name', 'nonull', '插件标识不能为空!', 2, 3), array('name', 'regexp:/^[a-zA-Z][a-zA-Z0-9_]+$/i', '插件标识只支持英文、数字', 2, 3), array('name', 'addonUniqueCheck', '该插件已经存在!', 2, 3), array('title', 'nonull', '插件名称不能为空!', 2, 3), array('version', 'nonull', '插件版本不能为空!', 2, 3), array('author', 'nonull', '插件作者不能为空!', 2, 3), array('description', 'nonull', '插件描述不能为空!', 2, 3));
if (!$this->db->validate($data)) {
$this->error($this->db->error);
}
$data['name'] = ucfirst($data['name']);
$addonDir = APP_ADDON_PATH . $data['name'] . '/';
//插件目录
//验证安装目录
if (!is_writable(APP_ADDON_PATH)) {
$this->error(APP_ADDON_PATH . ' 不可写');
}
is_dir($addonDir) or dir::create($addonDir);
//创建插件目录
//-------------------创建配置文件
if ($data['config']) {
copy(HDPHP_PATH . 'Lib/Tpl/configAddon.php', $addonDir . 'config.php');
}
//-----------------控制器
if ($data['has_adminlist'] || $data['has_outurl']) {
//创建控制器目录
is_dir($addonDir . 'Controller') or Dir::create($addonDir . 'Controller');
}
if ($data['has_adminlist']) {
$controller = <<<str
<?php
/**
* {$data['name']} 插件
* @author 后盾向军 <houdunwangxj@gmail.com>
*/
class AdminController extends AddonController {
public function index() {
\$this->display();
}
}
str;
file_put_contents($addonDir . 'Controller/AdminController.class.php', $controller);
}
//创建前台访问控制器
if ($data['has_outurl']) {
$controller = <<<str
<?php
/**
* {$data['name']} 插件
* @author 后盾向军 <houdunwangxj@gmail.com>
*/
class IndexController extends AddonController {
public function index() {
\$this->display();
}
}
str;
file_put_contents($addonDir . 'Controller/IndexController.class.php', $controller);
}
$addonData = <<<str
<?php
/**
* {$data['name']} 插件
* @author 后盾向军 <houdunwangxj@gmail.com>
*/
class {$data['name']}Addon extends Addon
{
//插件信息
public \$info = array(
'name' => '{$data['name']}',
'title' => '{$data['title']}',
'description' => '{$data['description']}',
'status' => 1,
'author' => '{$data['author']}',
'version' => '{$data['version']}',
'has_adminlist' => {$data['has_adminlist']},
);
//安装
public function install()
{
return true;
}
//卸载
public function uninstall()
{
return true;
}
str;
//.........这里部分代码省略.........
示例10: mkDirs
/**
* 创建项目运行目录
* @access private
* @return void
*/
public static function mkDirs()
{
if (is_dir(APP_COMMON_PATH)) {
return;
}
//目录
$dirs = array(APP_PATH, TEMP_PATH, APP_COMMON_PATH, APP_CONFIG_PATH, APP_ADDON_PATH, APP_MODEL_PATH, APP_CONTROLLER_PATH, APP_LANGUAGE_PATH, APP_HOOK_PATH, APP_TAG_PATH, APP_LIB_PATH, APP_COMPILE_PATH, APP_CACHE_PATH, APP_TABLE_PATH, APP_LOG_PATH, MODULE_CONTROLLER_PATH, MODULE_CONFIG_PATH, MODULE_LANGUAGE_PATH, MODULE_MODEL_PATH, MODULE_HOOK_PATH, MODULE_TAG_PATH, MODULE_LIB_PATH, MODULE_VIEW_PATH, CONTROLLER_VIEW_PATH, MODULE_PUBLIC_PATH, STATIC_PATH);
foreach ($dirs as $d) {
if (!dir_create($d, 0755)) {
header("Content-type:text/html;charset=utf-8");
exit("目录{$d}创建失败,请检查权限");
}
}
//复制视图
is_file(CONTROLLER_VIEW_PATH . "index.html") or copy(HDPHP_PATH . 'Lib/Tpl/view.html', CONTROLLER_VIEW_PATH . "index.html");
//复制公共模板文件
is_file(MODULE_PUBLIC_PATH . "success.html") or copy(HDPHP_PATH . 'Lib/Tpl/success.html', MODULE_PUBLIC_PATH . "success.html");
is_file(MODULE_PUBLIC_PATH . "error.html") or copy(HDPHP_PATH . 'Lib/Tpl/error.html', MODULE_PUBLIC_PATH . "error.html");
//复制模块配置文件
is_file(MODULE_CONFIG_PATH . "config.php") or copy(HDPHP_PATH . 'Lib/Tpl/configModule.php', MODULE_CONFIG_PATH . "config.php");
is_file(APP_CONFIG_PATH . "config.php") or copy(HDPHP_PATH . 'Lib/Tpl/configApp.php', APP_CONFIG_PATH . "config.php");
//创建测试控制器
is_file(MODULE_CONTROLLER_PATH . 'IndexController.class.php') or file_put_contents(MODULE_CONTROLLER_PATH . 'IndexController.class.php', file_get_contents(HDPHP_PATH . 'Lib/Tpl/controller.php'));
//创建安全文件
self::safeFile();
//批量创建模块
if (defined('MODULE_LIST')) {
$module = explode(',', MODULE_LIST);
if (!empty($module)) {
foreach ($module as $m) {
dir::create(APP_PATH . $m);
dir::copy(MODULE_PATH, APP_PATH . $m);
}
}
}
}
示例11: thumb
/**
*
* 图片裁切处理
* @param $img 操作的图片文件路径
* @param $outfile 输出文件路径
* @param path 缩略图存放路径
* @param $t_type 裁切图片的方式
* @param $t_w 缩略图宽度
* @param $t_h 缩略图高度
* return $string 处理后的文件名
*/
public function thumb($img, $outfile = '', $path = '', $t_w = '', $t_h = '', $t_type = '')
{
if (!$this->check($img)) {
return false;
}
//基础配置
$t_type = $t_type ? $t_type : $this->thumb_type;
$t_w = $t_w ? $t_w : $this->thumb_width;
$t_h = $t_h ? $t_h : $this->thumb_height;
$path = $path ? $path : C("THUMB_PATH");
//获得图像信息
$img_info = getimagesize($img);
$img_w = $img_info[0];
$img_h = $img_info[1];
$img_type = image_type_to_extension($img_info[2]);
//获得相关尺寸
$thumb_size = $this->thumb_size($img_w, $img_h, $t_w, $t_h, $t_type);
//原始图像资源
$func = "imagecreatefrom" . substr($img_type, 1);
$res_img = $func($img);
//缩略图的资源
if ($img_type == '.gif') {
$res_thumb = imagecreate($thumb_size[0], $thumb_size[1]);
$color = imagecolorallocate($res_thumb, 255, 0, 0);
} else {
$res_thumb = imagecreatetruecolor($thumb_size[0], $thumb_size[1]);
imagealphablending($res_thumb, false);
//关闭混色
imagesavealpha($res_thumb, true);
//储存透明通道
}
//绘制缩略图X
if (function_exists("imagecopyresampled")) {
imagecopyresampled($res_thumb, $res_img, 0, 0, 0, 0, $thumb_size[0], $thumb_size[1], $thumb_size[2], $thumb_size[3]);
} else {
imagecopyresized($res_thumb, $res_img, 0, 0, 0, 0, $thumb_size[0], $thumb_size[1], $thumb_size[2], $thumb_size[3]);
}
//处理透明色
if ($img_type == '.gif') {
imagecolortransparent($res_thumb, $color);
}
//配置输出文件名
$imgInfo = pathinfo($img);
$outfile = $outfile ? $outfile : $this->thumb_prefix . $imgInfo['filename'] . $this->thumb_endfix . "." . $imgInfo['extension'];
$upload_dir = $path ? $path : dirname($img);
dir::create($upload_dir);
$outfile = $upload_dir . '/' . $outfile;
$func = "image" . substr($img_type, 1);
$func($res_thumb, $outfile);
if (isset($res_img)) {
imagedestroy($res_img);
}
if (isset($res_thumb)) {
imagedestroy($res_thumb);
}
return $outfile;
}
示例12: checkDir
/**
* 验证目录
* @param string $path 目录
*/
public function checkDir($path)
{
return dir::create($path) && is_writeable($path) ? true : false;
}
示例13: set_save_path
/**
* 设置SESSION存储路径
* @param type $path
*/
static function set_save_path($path)
{
self::start();
if (!is_dir($path)) {
dir::create($path);
}
session_save_path($path);
}
示例14: getSaveFile
public function getSaveFile($savepath, $filename)
{
//返回实际目录
$dir = ZOTOP_PATH_ROOT . DS . $savepath;
//目录检测
if (!is_dir($dir) && !dir::create($dir, 0777)) {
$this->error = 8;
//目录不存在且无法自动创建
return false;
}
@chmod($dir, 0777);
if (!is_writeable($dir) && $dir != '/') {
$this->error = 9;
//不可写
return false;
}
$savefile = $dir . $filename;
return $savefile;
}
示例15: write
/**
* 写入文件
*
* @param string $file
* @param string $content
* @param boolean $overwrite
* @return boolean
*/
public static function write($file, $content = '', $overwrite = TRUE)
{
$file = path::decode($file);
//当目录不存在的情况下先创建目录
if (!dir::exists(dirname($file))) {
dir::create(dirname($file));
}
if (!file::exists($file) || $overwrite) {
return @file_put_contents($file, $content);
}
return false;
}