本文整理汇总了PHP中make_dir函数的典型用法代码示例。如果您正苦于以下问题:PHP make_dir函数的具体用法?PHP make_dir怎么用?PHP make_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_dir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: SaveHTTPFile
function SaveHTTPFile($fFileHTTPPath, $fFileSavePath, $fFileSaveName)
{
//记录程序开始的时间
$BeginTime = getmicrotime();
//取得文件名
$fFileSaveName = $fFileSavePath . "/" . $fFileSaveName;
make_dir(dirname($fFileSaveName));
//取得文件的内容
ob_start();
readfile($fFileHTTPPath);
$img = ob_get_contents();
ob_end_clean();
//$size = strlen($img);
//保存到本地
$fp2 = @fopen($fFileSaveName, "a");
fwrite($fp2, $img);
fclose($fp2);
/*加水印代码*/
require_once ROOT_PATH . 'includes/cls_image.php';
$ext = get_extension($fFileSaveName);
$fFileSaveName = convert_GIF_to_JPG($fFileSaveName);
if (CopyFiles($fFileSaveName)) {
$image = new cls_image();
$image->add_watermark($fFileSaveName, '', '../../../../' . $GLOBALS['waterMark']['watermark'], $GLOBALS['waterMark']['watermark_place'], $GLOBALS['waterMark']['watermark_alpha']);
}
if ($ext == 'gif' || $ext == '.gif') {
back_JPG_to_GIF($fFileSaveName);
}
/*加水印代码--end*/
//记录程序运行结束的时间
$EndTime = getmicrotime();
//返回运行时间
return $EndTime - $BeginTime;
}
开发者ID:norain2050,项目名称:benhu,代码行数:34,代码来源:ServerXMLHTTP.php
示例2: mb_template
function mb_template($temp_file = null, $options = null, $caller = null)
{
if ($options !== null) {
foreach ($options as $k => $v) {
if ($v !== null) {
$this->{$k} = $v;
}
}
}
$this->caller = $caller ? $caller : $this;
if ($temp_file != null) {
$this->temp_file = $temp_file;
}
if (substr($this->temp_dir, -1, 1) != '/' && substr($this->temp_dir, -1, 1) != '\\') {
$this->temp_dir .= '/';
}
if (substr($this->compile_dir, -1, 1) != '/' && substr($this->compile_dir, -1, 1) != '\\') {
$this->compile_dir .= '/';
}
$pos = strrpos($temp_file, "/");
if (false !== $pos) {
$dir_part = substr($temp_file, 0, $pos + 1);
$this->temp_dir .= $dir_part;
$this->compile_dir .= $dir_part;
$this->temp_file = substr($temp_file, $pos + 1, strlen($temp_file));
}
if (!file_exists($this->temp_dir . $this->temp_file)) {
$this->_raise_error('Template File "' . $this->temp_dir . $this->temp_file . '" doesn\'t exists.');
}
if (!make_dir($this->compile_dir)) {
$this->_raise_error('Cont\'t create template compile dir "' . $this->compile_dir . '".');
}
}
开发者ID:duanshuyong0,项目名称:Murloc,代码行数:33,代码来源:template.class.php
示例3: insert_page
function insert_page($cat_id, $title, $parent_cat_id)
{
global $database;
$title = trim($title);
if (1 > $cat_id) {
return;
}
$parent = (int) $database->get_one("SELECT page_id FROM " . TABLE_PREFIX . "pages WHERE cat_id = {$parent_cat_id} LIMIT 1");
$parent_section = '';
$parent_titles = array_reverse(get_parent_titles($parent));
foreach ($parent_titles as $parent_title) {
$parent_section .= page_filename($parent_title) . '/';
}
if ($parent_section == '/') {
$parent_section = '';
}
$link = '/' . $parent_section . page_filename($title);
$filename = WB_PATH . PAGES_DIRECTORY . $link . '.php';
make_dir(WB_PATH . PAGES_DIRECTORY . '/' . $parent_section);
$get_same_page = $database->query("SELECT page_id FROM " . TABLE_PREFIX . "pages WHERE link = '{$link}' LIMIT 1");
if ($get_same_page->numRows() > 0) {
echo "Page {$link} exists.";
return;
}
$q = "INSERT INTO " . TABLE_PREFIX . "pages (cat_id, page_title, menu_title, parent, template, target, visibility, searching, menu, language, admin_groups, viewing_groups, modified_when, modified_by)\n VALUES ({$cat_id}, '{$title}', '{$title}', {$parent}, '', '', 'public', '1', '3', 'CS', '1,2', '1', '" . time() . "', 1)";
$pages = $database->query($q);
if ($database->is_error()) {
echo $database->get_error();
return;
}
$page_id = $pages->handle->insert_id;
return $page_id;
}
开发者ID:tomasjakl,项目名称:parse-pohoda-xml,代码行数:33,代码来源:parse-categories.php
示例4: init_lang_tpl
public static function init_lang_tpl()
{
$dir = PHPDISK_ROOT . 'system/global/';
make_dir($dir);
$file = $dir . 'lang_settings.inc.php';
file_exists($file) ? require_once $file : lang_cache();
$file = $dir . 'tpl_settings.inc.php';
file_exists($file) ? require_once $file : tpl_cache();
if (count($tpl_settings)) {
foreach ($tpl_settings as $v) {
if ($v[actived] && $v[tpl_type] == 'user') {
$user_tpl_dir = $v[tpl_name];
}
if ($v[actived] && $v[tpl_type] == 'admin') {
$admin_tpl_dir = $v[tpl_name];
}
}
}
if (count($lang_settings)) {
foreach ($lang_settings as $v) {
if ($v[actived]) {
$lang_name = $v[lang_name];
}
}
}
$user_tpl_dir = $user_tpl_dir ? "templates/{$user_tpl_dir}/" : 'templates/default/';
$admin_tpl_dir = $admin_tpl_dir ? "templates/{$admin_tpl_dir}/" : 'templates/admin/';
$lang_name = $lang_name ? $lang_name : 'zh_cn';
return array('user_tpl_dir' => $user_tpl_dir, 'admin_tpl_dir' => $admin_tpl_dir, 'lang_name' => $lang_name);
}
开发者ID:saintho,项目名称:phpdisk,代码行数:30,代码来源:core.class.php
示例5: create_csv_file
function create_csv_file($opts, $pipe, $cmd = __FUNCTION__)
{
# set prefix
$prefix = 'create_csv';
# merge opts
$opts = merge_opts($opts, $pipe, 'file');
# get file opt
$file = get_opt($prefix, $opts, 'file');
if (!check_opt_set_type($cmd, $file, 'file', 'string')) {
return false;
}
# get fields opt
$fields = get_opt($prefix, $opts, 'fields');
if (!check_opt_set_type($cmd, $fields, 'fields', 'array_of_strings')) {
return false;
}
# get data opt
$data = get_opt($prefix, $opts, 'data');
if (!check_opt_set_type($cmd, $data, 'data', 'array')) {
return false;
}
# make parent dir
if (!make_dir($opts, dirname($file))) {
return false;
}
# create temp file
$file_handle = @fopen('php://temp/csv-out', 'w');
if (!$file_handle) {
return error($cmd, "cannot create temp CSV file");
}
# output the fields
if (!fputcsv($file_handle, $fields)) {
return error($cmd, "could not output the fields CSV file : {$file}");
}
# output the data
foreach ($data as $line_no => $line) {
if (!fputcsv($file_handle, $line)) {
return error($cmd, "could not output line {$line_no} to CSV file : {$file}");
}
}
# grab contents and close temp file
rewind($file_handle);
$text = stream_get_contents($file_handle);
fclose($file_handle);
# create file and
if (!file_put_contents($file, $text)) {
return error($cmd, "cannot store CSV data to file : {$file}");
}
# report
$lines = count($data);
debug_echo($cmd, "CSV file created ({$lines} lines) : {$file}");
# return
if ($pipe === false) {
return $file;
}
return array('file' => $file);
}
开发者ID:simpl,项目名称:datapipe,代码行数:57,代码来源:csv.php
示例6: cover_image
function cover_image($description, $upload_dir)
{
make_dir($upload_dir);
if (preg_match('/<img.+src="(.+?)">/i', $description, $image)) {
$file_name = random(rand(8, 12)) . '.jpg';
if (file_put_contents($upload_dir . '/' . $file_name, file_get_contents($image[1]))) {
return substr($upload_dir . '/' . $file_name, 3);
}
}
return '';
}
开发者ID:reake,项目名称:share-travel,代码行数:11,代码来源:baidu.php
示例7: make_dir
function make_dir($path, $write_file = 1)
{
if (!is_dir($path)) {
$str = dirname($path);
if ($str) {
make_dir($str . '/');
@mkdir($path, 0777);
if ($write_file) {
file_put_contents($path . 'index.htm', 'PHPDisk');
}
}
}
}
开发者ID:saintho,项目名称:phpdisk,代码行数:13,代码来源:core.post.php
示例8: upload_image
/**
* 图片上传的处理函数
*
* @access public
* @param array upload 包含上传的图片文件信息的数组
* @param array dir 文件要上传在$this->data_dir下的目录名。如果为空图片放在则在$this->images_dir下以当月命名的目录下
* @param array img_name 上传图片名称,为空则随机生成
* @return mix 如果成功则返回文件名,否则返回false
*/
function upload_image($upload, $dir = '', $img_name = '')
{
/* 没有指定目录默认为根目录images */
if (empty($dir)) {
/* 创建当月目录 */
$dir = date('Ym');
$dir = ROOT_PATH . $this->images_dir . '/' . $dir . '/';
} else {
/* 创建目录 */
$dir = ROOT_PATH . $this->data_dir . '/' . $dir . '/';
if ($img_name) {
$img_name = $dir . $img_name;
// 将图片定位到正确地址
}
}
/* 如果目标目录不存在,则创建它 */
if (!file_exists($dir)) {
if (!make_dir($dir)) {
/* 创建目录失败 */
$this->error_msg = sprintf($GLOBALS['_LANG']['directory_readonly'], $dir);
$this->error_no = ERR_DIRECTORY_READONLY;
return false;
}
}
if (empty($img_name)) {
$img_name = $this->unique_name($dir);
$img_name = $dir . $img_name . $this->get_filetype($upload['name']);
}
if (!$this->check_img_type($upload['type'])) {
$this->error_msg = $GLOBALS['_LANG']['invalid_upload_image_type'];
$this->error_no = ERR_INVALID_IMAGE_TYPE;
return false;
}
/* 允许上传的文件类型 */
$allow_file_types = '|GIF|JPG|JEPG|PNG|BMP|SWF|';
if (!check_file_type($upload['tmp_name'], $img_name, $allow_file_types)) {
$this->error_msg = $GLOBALS['_LANG']['invalid_upload_image_type'];
$this->error_no = ERR_INVALID_IMAGE_TYPE;
return false;
}
if ($this->move_file($upload, $img_name)) {
return str_replace(ROOT_PATH, '', $img_name);
} else {
$this->error_msg = sprintf($GLOBALS['_LANG']['upload_failure'], $upload['name']);
$this->error_no = ERR_UPLOAD_FAILURE;
return false;
}
}
开发者ID:diandengs,项目名称:RechoPHP,代码行数:57,代码来源:class.Image.php
示例9: make_dir
function make_dir($node, $path = null, $root = null)
{
if (is_null($root)) {
$root = ".." . DIRECTORY_SEPARATOR;
}
$root = trim($root, "/") . DIRECTORY_SEPARATOR;
$keep = false;
$ignore = false;
if ($node == "#keep#") {
$keep = true;
$node = null;
} else {
if ($node == "#ignore#") {
$ignore = true;
$node = null;
}
}
if (!is_null($node) && !is_array($node)) {
$path = $node;
}
if (!is_null($path)) {
$root = $root . $path . DIRECTORY_SEPARATOR;
if (!file_exists($root)) {
echo "> dir " . $root . "\n";
mkdir($root);
}
}
if ($keep) {
$keep = $root . ".gitkeep";
if (!file_exists($keep)) {
echo "> file " . $keep . "\n";
file_put_contents($keep, "");
}
} else {
if ($ignore) {
$ignore = $root . ".gitignore";
if (!file_exists($ignore)) {
echo "> file " . $ignore . "\n";
file_put_contents($ignore, "*");
}
}
}
if (is_array($node)) {
foreach ($node as $k => $v) {
make_dir($v, $k, $root);
}
}
}
开发者ID:jura-php,项目名称:jura,代码行数:48,代码来源:install.php
示例10: __construct
function __construct($opts)
{
$this->build_config($opts['config'], $opts['template']);
// fix paths
foreach (array('db', 'img') as $path) {
$this->cfg->rrd->paths->{$path} = absolute_path((string) $this->cfg->rrd->paths->{$path}, $opts['paths'][$path]);
if (!is_dir((string) $this->cfg->rrd->paths->{$path})) {
// create a path if not exsits
echo 'creating ' . $this->cfg->rrd->paths->{$path} . PHP_EOL;
make_dir((string) $this->cfg->rrd->paths->{$path});
}
}
$this->rrdtool = new rrdtool($this->cfg->rrd);
// echo $this->cfg->asXML() . PHP_EOL;
// print_r($this->cfg);
// exit;
}
开发者ID:ngorchilov,项目名称:lgr,代码行数:17,代码来源:rrd.main.class.php
示例11: createNewsAccessFile
/**
*
* @category modules
* @package news
* @author WebsiteBaker Project
* @copyright WebsiteBaker Org. e.V.
* @link http://websitebaker.org/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WebsiteBaker 2.8.3
* @requirements PHP 5.3.6 and higher
* @version $Id: save_post.php 1538 2011-12-10 15:06:15Z Luisehahne $
* @filesource $HeadURL: svn://isteam.dynxs.de/wb_svn/wb280/tags/2.8.3/wb/modules/news/save_post.php $
* @lastmodified $Date: 2011-12-10 16:06:15 +0100 (Sa, 10. Dez 2011) $
*
*/
function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
{
global $admin, $MESSAGE;
$sPagesPath = WB_PATH . PAGES_DIRECTORY;
$sPostsPath = $sPagesPath . '/posts';
// create /posts/ - directory if not exists
if (!file_exists($sPostsPath)) {
if (is_writable($sPagesPath)) {
make_dir(WB_PATH . PAGES_DIRECTORY . '/posts/');
} else {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
}
}
// check if /posts/ - dir is writable
if (!is_writable($sPostsPath . '/')) {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
}
/*
// delete old accessfile if link has changed
if (($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
if (!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink);
}
}
*/
// delete old accessfile if link has changed
if ($newLink != $oldLink && is_writable($sPagesPath . $oldLink . PAGE_EXTENSION)) {
if (!unlink($sPagesPath . $oldLink . PAGE_EXTENSION)) {
$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'] . ' - ' . $oldLink);
}
}
// all ok, now create new accessfile
$newFile = $sPagesPath . $newLink . PAGE_EXTENSION;
// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
$backSteps = preg_replace('@^' . preg_quote(WB_PATH) . '@', '', $sPostsPath);
$backSteps = str_repeat('../', substr_count($backSteps, '/'));
$content = '<?php' . "\n" . '// *** This file is generated by WebsiteBaker Ver.' . WB_VERSION . "\n" . '// *** Creation date: ' . date('c') . "\n" . '// *** Do not modify this file manually' . "\n" . '// *** WB will rebuild this file from time to time!!' . "\n" . '// *************************************************' . "\n" . "\t" . '$page_id = ' . $page_id . ';' . "\n" . "\t" . '$section_id = ' . $section_id . ';' . "\n" . "\t" . '$post_id = ' . $post_id . ';' . "\n" . "\t" . '$post_section = ' . $section_id . ';' . "\n" . "\t" . 'require(\'' . $backSteps . 'index.php\');' . "\n" . '// *************************************************' . "\n";
if (file_put_contents($newFile, $content) !== false) {
// Chmod the file
change_mode($newFile);
} else {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'], ADMIN_URL . '/pages/modify.php?page_id=' . $page_id);
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].': '.$newFile);
}
}
开发者ID:WebsiteBaker-modules,项目名称:News,代码行数:60,代码来源:save_post.php
示例12: wxch_file
function wxch_file($upload)
{
$dir = date('Ymdh');
$img_path = 'images' . '/' . $dir . '/';
$dir = ROOT_PATH . 'images' . '/' . $dir . '/';
if (!file_exists($dir)) {
if (!make_dir($dir)) {
$this->error_msg = sprintf($GLOBALS['_LANG']['directory_readonly'], $dir);
$this->error_no = ERR_DIRECTORY_READONLY;
return false;
}
}
$file_name = random_filename();
$path_name = $dir . $file_name;
file_put_contents($path_name, $upload);
$img_name = $img_path . $file_name;
return $img_name;
}
开发者ID:GYWang1983,项目名称:fruit,代码行数:18,代码来源:userinfo.php
示例13: rename_recursive_dirs
function rename_recursive_dirs($dirsource, $dirdest, $deep = 0)
{
if (true === is_dir($dirsource)) {
$dir = dir($dirsource);
while ($file = $dir->read()) {
if ($file[0] != ".") {
if (!is_dir($dirsource . "/" . $file)) {
copy($dirsource . "/" . $file, $dirdest . "/" . $file);
change_mode($dirdest . "/" . $file);
} else {
make_dir($dirdest . "/" . $file);
rename_recursive_dirs($dirsource . "/" . $file, $dirdest . '/' . $file, $deep + 1);
}
}
}
$dir->close();
}
if ($deep == 0) {
rm_full_dir($dirsource);
}
return true;
}
开发者ID:pixelhulk,项目名称:LEPTON,代码行数:22,代码来源:function.rename_recursive_dirs.php
示例14: init_lang_tpl
public static function init_lang_tpl()
{
global $C, $settings, $auth;
$dir = PHPDISK_ROOT . 'system/global/';
make_dir($dir);
$file = $dir . 'lang_settings.inc.php';
file_exists($file) ? require_once $file : lang_cache();
$file = $dir . 'tpl_settings.inc.php';
file_exists($file) ? require_once $file : tpl_cache();
if (count($tpl_settings)) {
foreach ($tpl_settings as $v) {
if ($v[actived] && $v[tpl_type] == 'user') {
$user_tpl_dir = $v[tpl_name];
}
if ($v[actived] && $v[tpl_type] == 'admin') {
$admin_tpl_dir = $v[tpl_name];
}
}
}
if (count($lang_settings)) {
foreach ($lang_settings as $v) {
if ($v[actived]) {
$lang_name = $v[lang_name];
}
}
}
if ($settings[open_switch_tpls]) {
$ptpl = gpc('ptpl', 'C', '');
$user_tpl_dir = $C[tpl_name] = $ptpl ? check_template($ptpl) ? $ptpl : $user_tpl_dir : $user_tpl_dir;
//$C[tpl_name] = $user_tpl_dir;
}
$arr = get_template_info($user_tpl_dir);
$is_fms = $arr['template_core'] == 'fms' && $auth[open_fms] ? 1 : 0;
$user_tpl_dir = $user_tpl_dir ? "templates/{$user_tpl_dir}/" : 'templates/default/';
$admin_tpl_dir = $admin_tpl_dir ? "templates/{$admin_tpl_dir}/" : 'templates/admin/';
$lang_name = $lang_name ? $lang_name : 'zh_cn';
return array('user_tpl_dir' => $user_tpl_dir, 'admin_tpl_dir' => $admin_tpl_dir, 'lang_name' => $lang_name, 'fms' => $is_fms);
}
开发者ID:saintho,项目名称:phpdisk,代码行数:38,代码来源:core.class.php
示例15: write
function write($log_type, $str)
{
$log_arr = array('cache_log', 'db_log');
if (in_array($log_type, $log_arr)) {
$log_dir = PHPDISK_ROOT . "system/{$log_type}/";
$log_file = $log_dir . date('Ymd') . '.php';
make_dir($log_dir);
$str = '<?php exit; ?>' . $str . LF;
$fp = fopen($log_file, 'ab');
if (!$fp) {
die("Logger: Can not open file <b>{$log_type}</b> .code:1");
}
if (is_writable($log_file)) {
if (!fwrite($fp, $str)) {
die("Logger: Can not write file <b>{$log_type}</b> .code:2");
}
} else {
die("Logger: Can not write file <b>{$log_type}</b> .code:3");
}
fclose($fp);
} else {
die("Logger: Logger write error!");
}
}
开发者ID:saintho,项目名称:phpdisk,代码行数:24,代码来源:logger.class.php
示例16: _create_post
function _create_post($post_id)
{
global $database, $admin, $MESSAGE;
$query_posts = $database->query("SELECT * FROM " . TABLE_PREFIX . "mod_news_posts WHERE `post_id` = '{$post_id}'");
if (!$query_posts || $query_posts->numRows() == 0) {
return false;
}
$res = $query_posts->fetchRow();
$link = $res['link'];
$page_id = $res['page_id'];
$section_id = $res['section_id'];
$sPagesPath = WB_PATH . PAGES_DIRECTORY;
$sPostsPath = $sPagesPath . '/posts';
if (!file_exists($sPostsPath)) {
if (is_writable($sPagesPath)) {
make_dir(WB_PATH . PAGES_DIRECTORY . '/posts/');
} else {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
}
}
if (!is_writable($sPostsPath . '/')) {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
}
$newFile = $sPagesPath . $link . PAGE_EXTENSION;
// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
$backSteps = preg_replace('@^' . preg_quote(WB_PATH) . '@', '', $sPostsPath);
$backSteps = str_repeat('../', substr_count($backSteps, '/'));
$content = '<?php' . "\n" . '// *** This file is generated by WebsiteBaker Ver.' . WB_VERSION . "\n" . '// *** Creation date: ' . date('c') . "\n" . '// *** Do not modify this file manually' . "\n" . '// *** WB will rebuild this file from time to time!!' . "\n" . '// *************************************************' . "\n" . "\t" . '$page_id = ' . $page_id . ';' . "\n" . "\t" . '$section_id = ' . $section_id . ';' . "\n" . "\t" . '$post_id = ' . $post_id . ';' . "\n" . "\t" . '$post_section = ' . $section_id . ';' . "\n" . "\t" . 'require(\'' . $backSteps . 'index.php\');' . "\n" . '// *************************************************' . "\n";
if (file_put_contents($newFile, $content) !== false) {
// Chmod the file
change_mode($newFile);
} else {
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'], ADMIN_URL . '/pages/modify.php?page_id=' . $page_id);
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].': '.$newFile);
}
}
开发者ID:WebsiteBaker-modules,项目名称:sysinfo,代码行数:36,代码来源:pages.php
示例17: make_thumb
/**
* 创建图片的缩略图
*
* @access public
* @param string $img 原始图片的路径
* @param int $thumb_width 缩略图宽度
* @param int $thumb_height 缩略图高度
* @param strint $path 指定生成图片的目录名
* @return mix 如果成功返回缩略图的路径,失败则返回false
*/
function make_thumb($img, $thumb_width = 0, $thumb_height = 0, $path = '', $bgcolor = '')
{
$gd = $this->gd_version();
//获取 GD 版本。0 表示没有 GD 库,1 表示 GD 1.x,2 表示 GD 2.x
if ($gd == 0) {
$this->error_msg = $GLOBALS['_LANG']['missing_gd'];
return false;
}
/* 检查缩略图宽度和高度是否合法 */
if ($thumb_width == 0 && $thumb_height == 0) {
return str_replace(ROOT_PATH, '', str_replace('\\', '/', realpath($img)));
}
/* 检查原始文件是否存在及获得原始文件的信息 */
$org_info = @getimagesize($img);
if (!$org_info) {
$this->error_msg = sprintf($GLOBALS['_LANG']['missing_orgin_image'], $img);
$this->error_no = ERR_IMAGE_NOT_EXISTS;
return false;
}
if (!$this->check_img_function($org_info[2])) {
$this->error_msg = sprintf($GLOBALS['_LANG']['nonsupport_type'], $this->type_maping[$org_info[2]]);
$this->error_no = ERR_NO_GD;
return false;
}
$img_org = $this->img_resource($img, $org_info[2]);
/* 原始图片以及缩略图的尺寸比例 */
$scale_org = $org_info[0] / $org_info[1];
/* 处理只有缩略图宽和高有一个为0的情况,这时背景和缩略图一样大 */
if ($thumb_width == 0) {
$thumb_width = $thumb_height * $scale_org;
}
if ($thumb_height == 0) {
$thumb_height = $thumb_width / $scale_org;
}
/* 创建缩略图的标志符 */
if ($gd == 2) {
$img_thumb = imagecreatetruecolor($thumb_width, $thumb_height);
} else {
$img_thumb = imagecreate($thumb_width, $thumb_height);
}
/* 背景颜色 */
if (empty($bgcolor)) {
$bgcolor = $this->bgcolor;
}
$bgcolor = trim($bgcolor, "#");
sscanf($bgcolor, "%2x%2x%2x", $red, $green, $blue);
$clr = imagecolorallocate($img_thumb, $red, $green, $blue);
imagefilledrectangle($img_thumb, 0, 0, $thumb_width, $thumb_height, $clr);
if ($org_info[0] / $thumb_width > $org_info[1] / $thumb_height) {
$lessen_width = $thumb_width;
$lessen_height = $thumb_width / $scale_org;
} else {
/* 原始图片比较高,则以高度为准 */
$lessen_width = $thumb_height * $scale_org;
$lessen_height = $thumb_height;
}
$dst_x = ($thumb_width - $lessen_width) / 2;
$dst_y = ($thumb_height - $lessen_height) / 2;
/* 将原始图片进行缩放处理 */
if ($gd == 2) {
imagecopyresampled($img_thumb, $img_org, $dst_x, $dst_y, 0, 0, $lessen_width, $lessen_height, $org_info[0], $org_info[1]);
} else {
imagecopyresized($img_thumb, $img_org, $dst_x, $dst_y, 0, 0, $lessen_width, $lessen_height, $org_info[0], $org_info[1]);
}
/* 创建当月目录 */
if (empty($path)) {
$dir = ROOT_PATH . $this->images_dir . '/' . date('Ym') . '/';
} else {
$dir = $path;
}
/* 如果目标目录不存在,则创建它 */
if (!is_dir($dir)) {
if (!make_dir($dir)) {
/* 创建目录失败 */
$this->error_msg = sprintf($GLOBALS['_LANG']['directory_readonly'], $dir);
$this->error_no = ERR_DIRECTORY_READONLY;
return false;
}
}
/* 如果文件名为空,生成不重名随机文件名 */
$filename = $this->unique_name($dir);
/* 生成文件 */
if (function_exists('imagejpeg')) {
$filename .= '.jpg';
imagejpeg($img_thumb, $dir . $filename);
} elseif (function_exists('imagegif')) {
$filename .= '.gif';
imagegif($img_thumb, $dir . $filename);
} elseif (function_exists('imagepng')) {
$filename .= '.png';
//.........这里部分代码省略.........
开发者ID:GavinLai,项目名称:ecmall,代码行数:101,代码来源:image.lib.php
示例18: mod_news_Upgrade
function mod_news_Upgrade()
{
global $database, $msg, $admin, $MESSAGE;
$callingScript = $_SERVER["SCRIPT_NAME"];
$tmp = 'upgrade-script.php';
$globalStarted = substr_compare($callingScript, $tmp, 0 - strlen($tmp), strlen($tmp)) === 0;
$sPagesPath = WB_PATH . PAGES_DIRECTORY;
$sPostsPath = $sPagesPath . '/posts';
// create /posts/ - directory if not exists
if (!file_exists($sPostsPath)) {
if (is_writable($sPagesPath)) {
make_dir(WB_PATH . PAGES_DIRECTORY . '/posts/');
} else {
if (!$globalStarted) {
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'];
} else {
$msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'] . '<br />';
return;
}
}
if ($globalStarted) {
echo 'directory "' . PAGES_DIRECTORY . '/posts/" created.<br />';
}
}
// check if new fields must be added
$doImportDate = true;
if (!$database->field_exists(TABLE_PREFIX . 'mod_news_posts', 'created_when')) {
if (!$database->field_add(TABLE_PREFIX . 'mod_news_posts', 'created_when', 'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
if ($globalStarted) {
echo $MESSAGE['RECORD_MODIFIED_FAILED'] . '<br />';
return;
} else {
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
}
}
if ($globalStarted) {
echo 'datafield `' . TABLE_PREFIX . 'mod_news_posts`.`created_when` added.<br />';
}
} else {
$doImportDate = false;
}
if (!$database->field_exists(TABLE_PREFIX . 'mod_news_posts', 'created_by')) {
if (!$database->field_add(TABLE_PREFIX . 'mod_news_posts', 'created_by', 'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
if ($globalStarted) {
echo $MESSAGE['RECORD_MODIFIED_FAILED'] . '<br />';
return;
} else {
$admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);
}
}
if ($globalStarted) {
echo 'datafield `' . TABLE_PREFIX . 'mod_news_posts`.`created_by` added.<br />';
}
}
// preset new fields `created_by` and `created_when` from existing values
if ($doImportDate) {
$sql = 'UPDATE `' . TABLE_PREFIX . 'mod_news_posts` ' . 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
$database->query($sql);
}
// now iterate through all existing accessfiles,
// write its creation date into database
$oDir = new DirectoryIterator($sPostsPath);
$count = 0;
foreach ($oDir as $fileinfo) {
$fileName = $fileinfo->getFilename();
if (!$fileinfo->isDot() && $fileName != 'index.php' && substr_compare($fileName, PAGE_EXTENSION, 0 - strlen(PAGE_EXTENSION), strlen(PAGE_EXTENSION)) === 0) {
// save creation date from old accessfile
if ($doImportDate) {
$link = '/posts/' . preg_replace('/' . preg_quote(PAGE_EXTENSION) . '$/i', '', $fileinfo->getFilename());
$sql = 'UPDATE `' . TABLE_PREFIX . 'mod_news_posts` SET ' . '`created_when`=' . $fileinfo->getMTime() . ' ' . 'WHERE `link`=\'' . $database->escapeString($link) . '\' ' . 'AND `created_when`= 0';
$database->query($sql);
}
// delete old access file
unlink($fileinfo->getPathname());
$count++;
}
}
unset($oDir);
if ($globalStarted && $count > 0) {
$msg[] = 'save date of creation from ' . $count . ' old accessfiles and delete these files.<br />';
}
// ************************************************
// Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
$sql = 'UPDATE `' . TABLE_PREFIX . 'mod_news_posts` ';
$sql .= 'SET `created_when`=`published_when` ';
$sql .= 'WHERE `published_when`<`created_when`';
$database->query($sql);
$sql = 'UPDATE `' . TABLE_PREFIX . 'mod_news_posts` ';
$sql .= 'SET `created_when`=`posted_when` ';
$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
$database->query($sql);
// ************************************************
// rebuild all access-files
$count = 0;
$backSteps = preg_replace('@^' . preg_quote(WB_PATH) . '@', '', $sPostsPath);
$backSteps = str_repeat('../', substr_count($backSteps, '/'));
$sql = 'SELECT `page_id`,`post_id`,`section_id`,`link` ';
$sql .= 'FROM `' . TABLE_PREFIX . 'mod_news_posts`';
$sql .= 'WHERE `link` != \'\'';
if ($resPosts = $database->query($sql)) {
//.........这里部分代码省略.........
开发者ID:WebsiteBaker-modules,项目名称:News,代码行数:101,代码来源:upgrade.php
示例19: upload_article_file
function upload_article_file($upload)
{
if (!make_dir("../" . DATA_DIR . "/article")) {
/* 创建目录失败 */
return false;
}
$filename = cls_image::random_filename() . substr($upload['name'], strpos($upload['name'], '.'));
$path = ROOT_PATH . DATA_DIR . "/article/" . $filename;
if (move_upload_file($upload['tmp_name'], $path)) {
return DATA_DIR . "/article/" . $filename;
} else {
return false;
}
}
开发者ID:norain2050,项目名称:mhFault,代码行数:14,代码来源:article.php
示例20:
<?php
/**
*
* @category modules
* @package news
* @author WebsiteBaker Project
* @copyright WebsiteBaker Org. e.V.
* @link http://websitebaker.org/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WebsiteBaker 2.8.3
* @requirements PHP 5.3.6 and higher
* @version $Id: install.php 1587 2012-01-24 23:19:06Z darkviper $
* @filesource $HeadURL: svn://isteam.dynxs.de/wb_svn/wb280/tags/2.8.3/wb/modules/news/install.php $
* @lastmodified $Date: 2012-01-25 00:19:06 +0100 (Mi, 25. Jan 2012) $
*
*/
if (defined('WB_PATH')) {
// create tables from sql dump file
if (is_readable(__DIR__ . '/install-struct.sql')) {
$database->SqlImport(__DIR__ . '/install-struct.sql', TABLE_PREFIX, __FILE__);
// Make news post access files dir
require_once WB_PATH . '/framework/functions.php';
if (make_dir(WB_PATH . PAGES_DIRECTORY . '/posts')) {
}
}
}
/* **** END INSTALL ********************************************************* */
开发者ID:WebsiteBaker-modules,项目名称:News,代码行数:28,代码来源:install.php
注:本文中的make_dir函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论