/** * 递归复制文件 * * @param $source 源文件或目录名 * @param $destination 目的文件或目录名 * @param $child 是不是包含的子目录 * @param $justnew 只拷贝新更改过的文件 * @param $exceprarr 被排除的文件夹数组 **/ public static function all_copy($source, $destination, $justnew = false, $exceprarr = array()) { if (!is_dir($source)) { if (!file_exists(dirname($destination))) { File::creat_dir(dirname($destination)); } if (!$justnew || !file_exists($destination) || filemtime($destination) < filemtime($source)) { @copy($source, $destination); } } else { self::creat_dir($destination); $handle = dir($source); while (($entry = $handle->read()) !== false) { if (strpos($entry, '.') !== 0 && !in_array($entry, $exceprarr)) { self::all_copy($source . "/" . $entry, $destination . "/" . $entry, $justnew, $exceprarr); } } } }
/** * elfinder 初始化设置 * * @param string $usrpath * @param string $usrurl * @param string $pathname * @param string $maxsize * @param arrat $allow * @param string $syspath * @param string $sysurl * @param string $sysname */ public static function set_elfinder($usrpath, $usrurl, $pathname = '我的图库', $maxsize = '500k', $allow = array('image'), $syspath = null, $sysurl = null, $sysname = '系统图库') { $_SESSION['yyuc_upload_path'] = $usrpath; File::creat_dir($usrpath); $_SESSION['yyuc_upload_url'] = $usrurl; $_SESSION['yyuc_upload_name'] = $pathname; $_SESSION['yyuc_upload_maxsize'] = $maxsize; $_SESSION['yyuc_upload_allow'] = $allow; $_SESSION['yyuc_media_path'] = $syspath; $_SESSION['yyuc_media_url'] = $sysurl; $_SESSION['yyuc_media_name'] = $sysname; $_SESSION['yyuc_elfinder_driver'] = 'LocalFileSystem'; return false; }
/** * 根据页面标识 存储上传的文件 通常用在Form提交中的预上传处理 * @param string $key 上传控件的的name值提交上来的属性 * @param string $folderpath pub文件夹下的相对文件夹路径 * @param string $isFile 上一参数是否是文件,如果是则直接覆盖文件 * @return string 此次存储的文件相对网站根目录的路径没有信息提交则返回false */ private static function _resave_upload_file($key, $folderpath = null, $isFile = false) { //临时目录清空 if (trim(Conf::$remote_path) != '') { $syspathp = Conf::$local_remote; $STA = Conf::$remote_path; } else { $syspathp = YYUC_FRAME_PATH . YYUC_PUB . '/'; $STA = '/'; } if (stripos($key, 'http') === 0) { //是修改且从未被修改过 return $key; } elseif (trim($key) == '') { //提交信息为空 return false; } elseif (strpos($key, '/') === 0) { //是修改且从未被修改过 return $key; } elseif (strpos($key, '@-@') === 0) { //删除上次的文件地址 @unlink($syspathp . substr($key, 4)); return false; } elseif (strpos($key, '@-@') !== false) { //修改后删除上次的文件地址 $keys = explode('@-@', $key); $key = $keys[0]; @unlink($syspathp . $keys[1]); } if ($folderpath === null) { $folderpath = 'upload/auto/' . date('Y/m/d', time()); } if (!$isFile) { File::creat_dir($syspathp . $folderpath); $tsubppath = str_replace('//', '/', $folderpath . '/' . basename($key)); $newpath = $syspathp . $folderpath . '/' . basename($key); } else { File::creat_dir_with_filepath($syspathp . $folderpath); $tsubppath = str_replace('//', '/', $folderpath); $newpath = $syspathp . $folderpath; } @unlink($newpath); rename($syspathp . $key, $newpath); return $STA . $tsubppath; }
<?php //验证设置 必须的!!! //access_control($fun); Page::$need_view = false; $subpath = 'upload/kindeditor/' . Request::get(1) . '/' . date("Ymd") . '/'; //文件保存目录路径 $save_path = YYUC_FRAME_PATH . YYUC_PUB . '/' . $subpath; File::creat_dir($save_path); //文件保存目录URL $save_url = Conf::$http_path . $subpath; //定义允许上传的文件扩展名 $ext_arr = array('image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2', 'pdf')); //最大文件大小 1M $max_size = 1000000; //有上传文件时 if (empty($_FILES) === false) { //原文件名 $file_name = $_FILES['imgFile']['name']; //服务器上临时文件名 $tmp_name = $_FILES['imgFile']['tmp_name']; if (stripos($file_name, '.php') !== false) { die; } if (stripos($tmp_name, '.php') !== false) { die; } //文件大小 $file_size = $_FILES['imgFile']['size']; //检查文件名 if (!$file_name) {