function Smarty_Serweb() { global $config, $_SERWEB; // Smarty does not support "magic_quotes_runtime" enabled // So make sure to disable it. ini_set("magic_quotes_runtime", 0); // Class Constructor. These automatically get set with each new instance. parent::__construct(); //set smarty directories $this->template_dir = array($_SERWEB["templatesdir"]); if ($_SERWEB["templatesdir"] != $_SERWEB["coretemplatesdir"]) { $this->template_dir[] = $_SERWEB["coretemplatesdir"]; } $this->config_dir = $_SERWEB["templatesdir"] . 'configs/'; $this->cache_dir = $_SERWEB["templatesdir"] . 'cache/'; $this->plugins_dir = array(); if (!empty($_SERWEB["smartypluginsdir"])) { $this->plugins_dir[] = $_SERWEB["smartypluginsdir"]; } $this->plugins_dir[] = $_SERWEB["corefunctionsdir"] . "smarty_plugins/"; $this->plugins_dir[] = $_SERWEB["smartydir"] . "plugins/"; if (!empty($config->smarty_compile_dir)) { RecursiveMkdir($config->smarty_compile_dir); $this->compile_dir = $config->smarty_compile_dir; } else { $this->compile_dir = $_SERWEB["templatesdir"] . 'templates_c/'; } }
function upload_image($input, $image = null, $type = 'page', $scale = false) { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $z = $_FILES[$input]; if ($z && strpos($z['type'], 'image') === 0 && $z['error'] == 0) { if (!$image) { RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$year}/{$day}"); $image = "{$type}/{$year}/{$day}/{$n}"; $path = IMG_ROOT . '/' . $image; } else { RecursiveMkdir(dirname(IMG_ROOT . '/' . $image)); $path = IMG_ROOT . '/' . $image; $postfixs = array_keys(get_image_size_map()); // $postfixs = array('_index','_big'); foreach ($postfixs as $fix) { $index_image = preg_replace('#(\\w+)\\.(\\w+)$#', "\\1_{$fix}.\\2", $path); unlink($index_image); } } move_uploaded_file($z['tmp_name'], $path); return $image; } return $image; }
function RecursiveMkdir($path) { if (!file_exists($path)) { RecursiveMkdir(dirname($path)); @mkdir($path, 0777); } }
/** * 递归创建目录函数 * * @param $path 路径,比如 "aa/bb/cc/dd/ee" * @param $mode 权限值,php中要用0开头,比如0777,0755 */ function recursiveMkdir($path, $mode) { if (!file_exists($path)) { RecursiveMkdir(dirname($path), $mode); mkdir($path, $mode); } }
function RecursiveMkdir($path) { if (!file_exists($path)) { RecursiveMkdir(dirname($path)); $old_umask = umask(0); mkdir($path, 0777); umask($old_umask); } }
function get_image($input, $image = null, $type = 'team', $scale = false) { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$year}/{$day}"); $image = "{$type}/{$year}/{$day}/{$n}"; $path = IMG_ROOT . '/' . $image; if (!grabImage($input, $path)){ return false; } if ($type == 'team' && $scale) { $npath = preg_replace('#(\d+)\.(\w+)$#', "\\1_index.\\2", $path); Image :: Convert($path, $npath, 200, 120, Image :: MODE_CUT); } return $image; }
function Smarty_Serweb() { global $config; //avoid smarty crash if "magic_quotes_runtime" is enabled in php.ini ini_set("magic_quotes_runtime", 0); // Class Constructor. These automatically get set with each new instance. $this->Smarty(); //set smarty directories $this->template_dir = SMARTY_DIR . '../templates/'; $this->config_dir = SMARTY_DIR . '../templates/configs/'; $this->cache_dir = SMARTY_DIR . '../templates/cache/'; if (!empty($config->smarty_compile_dir)) { RecursiveMkdir($config->smarty_compile_dir); $this->compile_dir = $config->smarty_compile_dir; } else { $this->compile_dir = SMARTY_DIR . '../templates/templates_c/'; } }
/** * Update domain directory for soecified domain * * @param string $did domain id * @return bool return TRUE on success, FALSE on failure */ function update_domain_dir($did) { global $data, $_SERWEB; $domain_dir = $_SERWEB["serwebdir"] . "domains/" . $did . "/"; $vf = new Version_file($domain_dir . "versions.ini.php"); /* Open file containing versions of other files Do not check for errors here - if there will be error in version file, the file will be recreated by values in DB */ $vf->open(); $local_versions = $vf->get_all_files(); /* get versions of files in DB */ if (false === ($files = $data->get_latest_file_versions($did, null))) { return false; } /* synchronize directory with DB */ foreach ($files as $file => $f_prop) { if ($f_prop['deleted']) { /* file should be deleted */ if (isset($local_versions[$file])) { $vf->remove_file($file); } if (file_exists($domain_dir . $file)) { rm($domain_dir . $file); } } elseif ($f_prop['dir']) { /* directory */ if (!file_exists($domain_dir . $file)) { RecursiveMkdir($domain_dir . $file, 0770); } } elseif (!isset($local_versions[$file]) or !file_exists($domain_dir . $file) or $local_versions[$file] < $f_prop['version']) { /* file should be updated/created */ $ds =& Domain_settings::singleton($did, $file); if (false === $ds->update_local_file($f_prop['version'])) { return false; } $vf->set_version($file, $f_prop['version']); } } $vf->close(); return true; }
public function uploadify_no_md5() { define('UPLOAD_ROOT_PATH', "/uploads/"); if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $year = date('Y'); $day = date('md'); $relative_path = "{$_REQUEST['folder']}/{$year}/{$day}/"; $targetPath = $_SERVER['DOCUMENT_ROOT'] . '/' . UPLOAD_ROOT_PATH . $relative_path; RecursiveMkdir($targetPath); // $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $file_extension = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION); $new_file_name = md5($_FILES['Filedata']['name'] . time()) . ".{$file_extension}"; $targetFile = str_replace('//', '/', $targetPath) . $new_file_name; $reletiveTargetFile = str_replace('//', '/', $relative_path) . $new_file_name; // echo $reletiveTargetFile; echo $reletiveTargetFile . "||" . $_FILES['Filedata']['name']; move_uploaded_file($tempFile, iconv("UTF-8", "gb2312", $targetFile)); } }
<?php if (!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) { exit('Access Denied'); } define('LONGSUN_PATH', DISCUZ_ROOT . 'source/plugin/longsun_collect/'); define('FUN_PATH', LONGSUN_PATH . 'functions/'); define('DATA_PATH', LONGSUN_PATH . 'data/'); define('WORD_LIB_PATH', DATA_PATH . 'word_lib.txt'); require_once FUN_PATH . 'common.php'; if ($_POST) { RecursiveMkdir(DATA_PATH); $word_lib = trim($_POST['word_lib']); $word_lib = preg_split('/[\\s,]+/', $word_lib, -1, PREG_SPLIT_NO_EMPTY); $lib_array = array(); foreach ($word_lib as $k => $one) { preg_match_all('/(.*)(=|->)(.*)/', $one, $match); $lib_array[$k]['left_str'] = trim($match[1][0]); $lib_array[$k]['mark'] = trim($match[2][0]); $lib_array[$k]['right_str'] = trim($match[3][0]); } $save_lib = serialize($lib_array); $handle = fopen(WORD_LIB_PATH, 'w+'); fwrite($handle, $save_lib); fclose($handle); cpmsg(lang('plugin/longsun_collect', 'adv_success')); } $word_lib_str = file_get_contents(WORD_LIB_PATH); $word_lib_str = unserialize($word_lib_str); include template('longsun_collect:advance');
function get_page_screenshot($url, $image, $width = 600) { if (!$width) { $width = 600; } $shot_server = 'http://shot.lhls.com.cn/shot.php'; $img_content = Utility::DoGet($shot_server . '?w=' . $width . '&url=' . urlencode($url)); if (!$img_content) { return null; } // 如果存在原图,将原图的各个后缀的预览图删除 if ($image) { RecursiveMkdir(dirname(IMG_ROOT . '/' . $image)); $postfixs = array_keys(get_image_size_map()); foreach ($postfixs as $fix) { $index_image = preg_replace('#(\\w+)\\.(\\w+)$#', "\\1_{$fix}.\\2", $path); unlink($index_image); } } else { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $full_path = IMG_ROOT . "/screenshot/{$year}/{$day}"; RecursiveMkdir($full_path); $image = "/screenshot/{$year}/{$day}/{$n}"; } $path = str_replace('//', '/', IMG_ROOT . '/' . $image); $fimage = fopen($path, 'w'); fwrite($fimage, $img_content); fclose($fimage); return $image; }
public function save_image($image_url) { $IMG_ROOT = '/home/wwwroot/fordcms/'; //注意修改图片路径 // $IMG_ROOT = 'E:/workplace/simplecms/'; $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $full_path = $IMG_ROOT . "/Uploads/old_data/image/{$year}/{$day}"; RecursiveMkdir($full_path); $image = "/Uploads/old_data/image/{$year}/{$day}/{$n}"; $path = $IMG_ROOT . $image; // 中文标题的内容 $image_url = str_replace(array('%3A', '%2F'), array(':', '/'), urlencode($image_url)); $image_content = file_get_contents($image_url); $fimage = fopen($path, 'w'); fwrite($fimage, $image_content); fclose($fimage); return $image; }
/** * Write changes back to versions file * * @return bool TRUE on success or FALSE on error */ function close() { $dirname = dirname($this->filename); if (!file_exists($dirname)) { RecursiveMkdir($dirname, 0770); } $fp = fopen($this->filename, "w"); /* protect file from reading throught the web */ fwrite($fp, "; <?php die( 'Please do not access this page directly.' ); ?" . ">\n"); foreach ($this->versions as $file => $version) { fwrite($fp, $file . " = " . $version . "\n"); } fclose($fp); return true; }
/** * This function creates the specified directory using mkdir(). Note * that the recursive feature on mkdir() is added in PHP5 so I need * to create it myself for PHP4 * * @param string $path * @param int $mode The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page. */ function RecursiveMkdir($path, $mode = 0777) { if (!file_exists($path)) { // The directory doesn't exist. Recurse, passing in the parent // directory so that it gets created. RecursiveMkdir(dirname($path)); mkdir($path, $mode); } }
<?php require_once dirname(__FILE__) . '/app.php'; need_login(); list($year, $day) = explode('-', date('Y-md')); $save_path = IMG_ROOT . "/team/{$year}/{$day}/"; RecursiveMkdir($save_path); $save_url = WWW_ROOT . "/static/team/{$year}/{$day}/"; $ext_arr = array('gif', 'jpg', 'jpeg', 'png', 'bmp'); $max_size = 4096000; //4M File if (empty($_FILES) === false) { $file_name = $_FILES['imgFile']['name']; $tmp_name = $_FILES['imgFile']['tmp_name']; $file_size = $_FILES['imgFile']['size']; $info = Image::getImageType($tmp_name); if (empty($info)) { alert("请上传合法文件"); } if (!$file_name) { alert("请选择文件"); } if (!@is_dir($save_path)) { alert("上传目录不存在"); } if (!@is_writable($save_path)) { alert("上传目录没有写权限"); } if (!@is_uploaded_file($tmp_name)) { alert("临时文件不是上传文件"); }
phplib_load("sess"); require $_SERWEB["serwebdir"] . "load_lang.php"; phplib_load(array("auth", "perm")); require $_SERWEB["serwebdir"] . "../modules/multidomain/domain_settings.php"; phplib_load(); $perm->check("admin"); /* check if domain is set */ if (empty($sess_page_controler_domain_id)) { die("Domain ID is not set - permission denied"); } /* directory within domain dir */ $domain_dir_prefix = "/img"; /* create path to image directory */ $doc_root = dirname(__FILE__) . "/../../../../../domains/" . $sess_page_controler_domain_id . $domain_dir_prefix; if (!file_exists($doc_root)) { RecursiveMkdir($doc_root, 0770); } $doc_root = realpath($doc_root); /* create directory if not exists */ //RecursiveMkdir($doc_root); $base_url = $config->domains_path . $sess_page_controler_domain_id . $domain_dir_prefix; /* MY_DOCUMENT_ROOT File system path to the directory you want to manage the files and folders NOTE: This directory requires write permission by PHP. That is, PHP must be able to create files in this directory. NOTE2: without trailing slash */ $MY_DOCUMENT_ROOT = $doc_root; //* system path to the directory you want to manage the files and folders //$MY_DOCUMENT_ROOT = 'D:/data/iptel/serweb/serweb/_data/'; //* system path to the directory you want to manage the files and folders
function upload_avatar($inputname, $username, $type = 'user') { $prefix = substr($username . "a", 0, 2); $n = $username . '.png'; $z = $_FILES[$inputname]; if ($z && strpos($z['type'], 'image') === 0 && $z['error'] == 0) { RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$prefix}"); $image = "{$type}/{$prefix}/{$n}"; $path = IMG_ROOT . '/' . $image; Image::Convert($z['tmp_name'], $path, 72, 72, Image::MODE_CUT, Image::SAVE_PNG); return $image; } return true; }
function uploadfile($inputname) { $immediate = isset($_GET['immediate']) ? $_GET['immediate'] : 0; $attachdir = 'upload'; //上传文件保存路径,结尾不要带/ $dirtype = 1; //1:按天存入目录 2:按月存入目录 3:按扩展名存目录 建议使用按天存 $maxattachsize = 2097152; //最大上传大小,默认是2M $upext = 'txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid'; //上传扩展名 $msgtype = 2; //返回上传参数的格式:1,只返回url,2,返回参数数组 $err = ""; $msg = ""; if (!isset($_FILES[$inputname])) { return array('err' => 'Filename error or no file choosen', 'msg' => $msg); } $upfile = $_FILES[$inputname]; if (!empty($upfile['error'])) { switch ($upfile['error']) { case '1': $err = 'file size has succeeded the value defined in php.ini by upload_max_filesize'; break; case '2': $err = 'file size has succeeded defined MAX_FILE_SIZE value in HTML'; break; case '3': $err = 'file upload is not completed'; break; case '4': $err = 'no file to be uploaded'; break; case '6': $err = 'don not have temp folder'; break; case '7': $err = 'fail in writing file'; break; case '8': $err = 'interrupted by others while uploading'; break; case '999': default: $err = 'invalide error code'; } } elseif (empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none') { $err = 'no file to be uploaded'; } else { $temppath = $upfile['tmp_name']; $fileinfo = pathinfo($upfile['name']); $extension = strtolower($fileinfo['extension']); if (preg_match('/' . str_replace(',', '|', $upext) . '/i', $extension)) { $filesize = filesize($temppath); if ($filesize > $maxattachsize) { $err = 'file size succeeds ' . $maxattachsize . ' Bytes'; } else { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $attach_dir = IMG_ROOT . "/team/{$year}/{$day}"; RecursiveMkdir(IMG_ROOT . "/team/{$year}/{$day}"); $fname = time() . rand(1000, 9999) . '.' . $extension; $target = $attach_dir . '/' . $fname; move_uploaded_file($upfile['tmp_name'], $target); $target = WEB_ROOT . "/static/team/{$year}/{$day}/{$fname}"; if ($immediate == '1') { $target = '!' . $target; } if ($msgtype == 1) { $msg = $target; } else { $msg = array('url' => $target, 'localname' => $upfile['name'], 'id' => '1'); } //id参数固定不变,仅供演示,实际项目中可以是数据库ID } } else { $err = 'extension of file uploading should be: ' . $upext; } @unlink($temppath); } return array('err' => $err, 'msg' => $msg); }
function upload_image($input, $image = null, $type = 'team', $scale = false) { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $z = $_FILES[$input]; $filename = $z["tmp_name"]; $image_size = getimagesize($filename); if ($z && strpos($z['type'], 'image') === 0 && $z['error'] == 0) { if (!$image) { RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$year}/{$day}"); $image = "{$type}/{$year}/{$day}/{$n}"; $path = IMG_ROOT . '/' . $image; } else { RecursiveMkdir(dirname(IMG_ROOT . '/' . $image)); $path = IMG_ROOT . '/' . $image; } if ($type == 'user') { Image::Convert($z['tmp_name'], $path, 48, 48, Image::MODE_CUT); } else { if ($type == 'team') { move_uploaded_file($z['tmp_name'], $path); mark_image($image_size, $path, IMG_ROOT . '/logo.png'); } } if ($type == 'team' && $scale) { $npath = preg_replace('#(\\d+)\\.(\\w+)$#', "\\1_index.\\2", $path); Image::Convert($path, $npath, 190, 120, Image::MODE_CUT); } return $image; } return $image; }
function upload_image($inputname, $image = null, $type = 'team', $width = 440) { $year = date('Y'); $day = date('md'); $n = time() . rand(1000, 9999) . '.jpg'; $z = $_FILES[$inputname]; if ($z && strpos($z['type'], 'image') === 0 && $z['error'] == 0) { if (!$image) { RecursiveMkdir(IMG_ROOT . '/' . "{$type}/{$year}/{$day}"); $image = "{$type}/{$year}/{$day}/{$n}"; $path = IMG_ROOT . '/' . $image; } else { RecursiveMkdir(dirname(IMG_ROOT . '/' . $image)); $path = IMG_ROOT . '/' . $image; } if ($type == 'user') { Image::Convert($z['tmp_name'], $path, 48, 48, Image::MODE_CUT); } else { if ($type == 'team') { Image::Convert($z['tmp_name'], $path, $width, 0, Image::MODE_SCALE); } else { if ($type == 'charity') { Image::convert($z['tmp_name'], $path, 0, 0, Image::MODE_SCALE); } } } return $image; } return $image; }
function upload_file($input_name, $type = 'page') { $year = date('Y'); $day = date('md'); $time = date('Hmis'); $z = $_FILES[$input_name]; if ($z && $z['error'] == 0) { $file_info = pathinfo($z["name"]); $n = md5($z['name']) . $time . "." . $file_info['extension']; RecursiveMkdir(C('WWW_ROOT') . "/Uploads/" . "{$type}/{$year}/{$day}"); $file = "{$type}/{$year}/{$day}/{$n}"; $path = C('WWW_ROOT') . "/Uploads/" . $file; $path = iconv("utf-8", "gbk", $path); move_uploaded_file($z["tmp_name"], $path); } return $file; }
function uploadfile($inputname) { global $INI; $immediate=isset($_GET['immediate'])?$_GET['immediate']:0; $attachdir='upload';//上传文件保存路径,结尾不要带/ $dirtype=1;//1:按天存入目录 2:按月存入目录 3:按扩展名存目录 建议使用按天存 $maxattachsize=2097152;//最大上传大小,默认是2M $upext='txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid';//上传扩展名 $msgtype=2;//返回上传参数的格式:1,只返回url,2,返回参数数组 $err = ""; $msg = ""; if(!isset($_FILES[$inputname]))return array('err'=>'文件域的name错误或者没选择文件','msg'=>$msg); $upfile=$_FILES[$inputname]; if(!empty($upfile['error'])) { switch($upfile['error']) { case '1': $err = '文件大小超过了php.ini定义的upload_max_filesize值'; break; case '2': $err = '文件大小超过了HTML定义的MAX_FILE_SIZE值'; break; case '3': $err = '文件上传不完全'; break; case '4': $err = '无文件上传'; break; case '6': $err = '缺少临时文件夹'; break; case '7': $err = '写文件失败'; break; case '8': $err = '上传被其它扩展中断'; break; case '999': default: $err = '无有效错误代码'; } } elseif(empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none')$err = '无文件上传'; else { $fileinfo=pathinfo($upfile['name']); $extension=strtolower($fileinfo['extension']); if(preg_match('/'.str_replace(',','|',$upext).'/i',$extension)) { $filesize=$upfile['size']; if($filesize > $maxattachsize)$err='文件大小超过'.$maxattachsize.'字节'; else { $year = date('Y'); $day = date('md'); $fname = time().rand(1000,9999).'.jpg'; $attach_dir = IMG_ROOT . "/team/{$year}/{$day}"; RecursiveMkdir( IMG_ROOT . "/team/{$year}/{$day}" ); $target = $attach_dir.'/'.$fname; if ( is_resource($upfile['tmp_name']) ) { $data = fread($upfile['tmp_name'], $filesize); file_put_contents($target, $data); fclose($upfile['tmp_name']); } else { move_uploaded_file($upfile['tmp_name'],$target); @unlink($upfile['tmp_name']); } $target = $INI['system']['imgprefix']."/static/team/{$year}/{$day}/{$fname}"; if($immediate=='1')$target='!'.$target; if($msgtype==1)$msg=$target; else $msg=array('url'=>$target,'localname'=>$upfile['name'],'id'=>'1');//id参数固定不变,仅供演示,实际项目中可以是数据库ID } } else $err='上传文件扩展名必需为:'.$upext; if (is_resource($upfile['tmp_name'])) {fclose($upfile['tmp_name']);} else { @unlink($upfile['tmp_name']); } } return array('err'=>$err,'msg'=>$msg); }
function upload_image($input, $image=null, $type='team', $scale=false) { $year = date('Y'); $day = date('md'); $n = time().rand(1000,9999).'.jpg'; $z = $_FILES[$input]; if ($z && strpos($z['type'], 'image')===0 && $z['error']==0) { if (!$image) { RecursiveMkdir( IMG_ROOT . '/' . "{$type}/{$year}/{$day}" ); $image = "{$type}/{$year}/{$day}/{$n}"; $path = IMG_ROOT . '/' . $image; } else { RecursiveMkdir( dirname(IMG_ROOT .'/' .$image) ); $path = IMG_ROOT . '/' .$image; } if ($type=='user') { Image::Convert($z['tmp_name'], $path, 48, 48, Image::MODE_CUT); } else if($type=='team') { move_uploaded_file($z['tmp_name'], $path); }else if($type == 'activity'){ move_uploaded_file($z['tmp_name'], $path); } if($type=='team' && $scale) { $npath = preg_replace('#(\d+)\.(\w+)$#', "\\1_index.\\2", $path); Image::Convert($path, $npath, 234, 141, Image::MODE_CUT); $index2_path = preg_replace('#(\d+)\.(\w+)$#', "\\1_index2.\\2", $path); Image::Convert($path, $index2_path, 130, 79, Image::MODE_CUT); $index3_path = preg_replace('#(\d+)\.(\w+)$#', "\\1_index3.\\2", $path); Image::Convert($path, $index3_path, 75, 45, Image::MODE_CUT); } return $image; } return $image; }