/** * @param int $mode The mode. Default is 0777 - umask. * @return bool TRUE if the directory has been successfully created, FALSE otherwise. * @throws EyeIOException * @throws EyeInvalidArgumentException */ public function mkdir($mode = null) { if ($this->realFile === null) { throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path); } if ($mode === null) { $mode = 0777 & ~$this->getUMask(); } if (!is_int($mode)) { throw new EyeInvalidArgumentException($mode . ' is not a valid octal value for $mode.'); } $this->getParentFile()->checkWritePermission(); if ($this->realFile->mkdir()) { MetaManager::getInstance()->deleteMeta($this); $meta = MetaManager::getInstance()->getNewMetaDataInstance($this); if ($meta !== null) { $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $group = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosGroup(); $meta->set(self::METADATA_KEY_OWNER, $currentUser->getName()); $meta->set(self::METADATA_KEY_GROUP, $group->getName()); $meta->set(self::METADATA_KEY_CREATIONTIME, time()); $meta->set(self::METADATA_KEY_MODIFICATIONTIME, time()); $meta->set(self::METADATA_KEY_PERMISSIONS, AdvancedPathLib::permsToUnix($mode)); $this->setMeta($meta); } //notify listeners on the parent directory $this->getParentFile()->fireEvent('directoryCreated', new FileEvent($this)); return true; } return false; }
/** * @brief 设置上传文件存放目录 * @param String $dir 文件存放目录 */ function setDir($dir) { if ($dir != '' && !is_dir($dir)) { IFile::mkdir($dir); } $dir = strtr($dir, '\\', '/'); $this->dir = substr($dir, 0, -1) == '/' ? $dir : $dir . '/'; }
function __construct($ctrlRes = null) { $this->ctrlRes = $ctrlRes; if (isset(IWeb::$app->config['dbbackup']) && IWeb::$app->config['dbbackup'] != null) { $this->dir = IWeb::$app->config['dbbackup']; } if (!file_exists($this->dir)) { IFile::mkdir($this->dir); } }
/** * @brief 写入缓存 * @param string $key 缓存的唯一key值 * @param mixed $data 要写入的缓存数据 * @param int $expire 缓存数据失效时间,单位:秒 * @return bool true:成功;false:失败; */ public function set($key, $data, $expire = '') { $fileName = $this->getFileName($key); if (!file_exists($dirname = dirname($fileName))) { IFile::mkdir($dirname); } $writeLen = file_put_contents($fileName, $data); if ($writeLen == 0) { return false; } else { $expire = time() + $expire; touch($fileName, $expire); return true; } }
function __construct($ctrlRes = null) { if (is_array($ctrlRes)) { sort($ctrlRes); } $this->ctrlRes = $ctrlRes; if (isset(IWeb::$app->config['dbbackup']) && IWeb::$app->config['dbbackup'] != null) { $this->dir = IWeb::$app->config['dbbackup']; } if (isset(IWeb::$app->config['DB']['tablePre'])) { $this->tablePre = IWeb::$app->config['DB']['tablePre']; } if (!file_exists($this->dir)) { IFile::mkdir($this->dir); } }
/** * @brief 生成缩略图 * @param string $fileName 原图路径 * @param int $width 缩略图的宽度 * @param int $height 缩略图的高度 * @param string $extName 缩略图文件名附加值 * @param string $saveDir 缩略图存储目录 * @return string 缩略图文件名 */ public static function thumb($fileName, $width = 200, $height = 200, $extName = '_thumb', $saveDir = '') { $GD = new GD($fileName); if ($GD) { $GD->resize($width, $height); $GD->pad($width, $height); //存储缩略图 if ($saveDir && IFile::mkdir($saveDir)) { //生成缩略图文件名 $thumbBaseName = $extName . basename($fileName); $thumbFileName = $saveDir . basename($thumbBaseName); $GD->save($thumbFileName); return $thumbFileName; } else { return $GD->show(); } } return null; }
/** * @brief 写日志 * @param array $content loginfo数组 * @return bool 操作结果 */ public function write($logs = array()) { if (!is_array($logs) || empty($logs)) { throw new IException('the $logs parms must be array'); } if ($this->path == '') { throw new IException('the file path is undefined'); } $content = join("\t", $logs) . "\t\r\n"; //生成路径 $fileName = $this->path; if (!file_exists($dirname = dirname($fileName))) { IFile::mkdir($dirname); } $result = error_log($content, 3, $fileName); if ($result) { return true; } else { return false; } }
/** * @brief 对字符串进行普通的过滤处理 * @param string $str 被过滤的字符串 * @param int $limitLen 限定字符串的字节数 * @return string 被过滤后的字符串 * @note 仅对于部分如:<script,<iframe等标签进行过滤 */ public static function text($str, $limitLen = false) { $str = self::limitLen($str, $limitLen); $str = trim($str); require_once FCPATH . 'libs/htmlpurifier/HTMLPurifier.php'; $cache_dir = IWeb::$app->getRuntimePath() . "htmlpurifier/"; if (!file_exists($cache_dir)) { IFile::mkdir($cache_dir); } $config = HTMLPurifier_Config::createDefault(); //配置 允许flash $config->set('HTML.SafeEmbed', true); $config->set('HTML.SafeObject', true); $config->set('Output.FlashCompat', true); //配置 缓存目录 $config->set('Cache.SerializerPath', $cache_dir); //设置cache目录 //允许<a>的target属性 $def = $config->getHTMLDefinition(true); $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top'); $purifier = new HTMLPurifier($config); //过略掉所有<script>,<i?frame>标签的on事件,css的js-expression、import等js行为,a的js-href $str = $purifier->purify($str); return self::addSlash($str); }
/** * @brief 开始执行上传 * @return array 包含上传成功信息的数组 * $file = array( * name 如果上传成功,则返回上传后的文件名称,如果失败,则返回客户端名称 * size 上传附件大小 * fileSrc 上传文件完整路径 * dir 上传目录 * ininame 上传图片名 * flag -1:上传的文件超出服务器限制; -2:上传的文件超出浏览器限制; -3:上传的文件被部分上传; -4:没有找到上传的文件; -5:上传的文件丢失; * -6:上传的临时文件没有正确写入; -7:扩展名不允许上传; -8:上传的文件超出了程序的限制; -9:上传的文件中有木马病毒 ; 1:上传成功; * ext 上传附件扩展名 * ); */ public function execute() { //总的文件上传信息 $info = array(); foreach ($_FILES as $field => $file) { $fileInfo = array(); //不存在上传的文件名 if (!isset($_FILES[$field]['name']) || $_FILES[$field]['name'] == '') { continue; } //上传控件为数组格式 file[]格式 if (is_array($_FILES[$field]['name'])) { $keys = array_keys($_FILES[$field]['name']); foreach ($keys as $key) { $fileInfo[$key]['name'] = $_FILES[$field]['name'][$key]; //上传出现错误 if (isset($_FILES[$field]['error'][$key]) && $_FILES[$field]['error'][$key] != 0) { $fileInfo[$key]['flag'] = 0 - $_FILES[$field]['error'][$key]; } else { //获取扩展名 $fileext = IFile::getFileType($_FILES[$field]['tmp_name'][$key]); if (is_array($fileext) || $fileext == null) { $fileext = IFile::getFileSuffix($_FILES[$field]['name'][$key]); } //图片木马检测 if (in_array($fileext, $this->checkType) && !IFilter::checkHex($_FILES[$field]['tmp_name'][$key])) { $fileInfo[$key]['flag'] = -9; } else { /*开始上传文件*/ //(1)上传类型不符合 if (!in_array($fileext, $this->allowType)) { $fileInfo[$key]['flag'] = -7; } else { if ($_FILES[$field]['size'][$key] > $this->maxsize) { $fileInfo[$key]['flag'] = -8; } else { //修改图片状态值 $fileInfo[$key]['name'] = ITime::getDateTime('Ymdhis') . mt_rand(100, 999) . '.' . $fileext; $fileInfo[$key]['dir'] = $this->dir; $fileInfo[$key]['size'] = $_FILES[$field]['size'][$key]; $fileInfo[$key]['ininame'] = $_FILES[$field]['name'][$key]; $fileInfo[$key]['ext'] = $fileext; $fileInfo[$key]['fileSrc'] = $fileInfo[$key]['dir'] . $fileInfo[$key]['name']; $fileInfo[$key]['flag'] = 1; if ($this->isForge == false) { if (is_uploaded_file($_FILES[$field]['tmp_name'][$key])) { IFile::mkdir($this->dir); move_uploaded_file($_FILES[$field]['tmp_name'][$key], $this->dir . $fileInfo[$key]['name']); } } else { IFile::xcopy($_FILES[$field]['tmp_name'][$key], $this->dir . $fileInfo[$key]['name']); } } } } } } } else { $fileInfo[0]['name'] = $_FILES[$field]['name']; //上传出现错误 if (isset($_FILES[$field]['error']) && $_FILES[$field]['error'] != 0) { $fileInfo[0]['flag'] = 0 - $_FILES[$field]['error']; } else { //获取扩展名 $fileext = IFile::getFileType($_FILES[$field]['tmp_name']); if (is_array($fileext) || $fileext == null) { $fileext = IFile::getFileSuffix($_FILES[$field]['name']); } //图片木马检测 if (in_array($fileext, $this->checkType) && !IFilter::checkHex($_FILES[$field]['tmp_name'])) { $fileInfo[0]['flag'] = -9; } else { /*开始上传文件*/ //(1)上传类型不符合 if (!in_array($fileext, $this->allowType)) { $fileInfo[0]['flag'] = -7; } else { if ($_FILES[$field]['size'] > $this->maxsize) { $fileInfo[0]['flag'] = -8; } else { //修改图片状态值 $fileInfo[0]['name'] = ITime::getDateTime('YmdHis') . mt_rand(100, 999) . '.' . $fileext; $fileInfo[0]['dir'] = $this->dir; $fileInfo[0]['size'] = $_FILES[$field]['size']; $fileInfo[0]['ininame'] = $_FILES[$field]['name']; $fileInfo[0]['ext'] = $fileext; $fileInfo[0]['fileSrc'] = $fileInfo[0]['dir'] . $fileInfo[0]['name']; $fileInfo[0]['flag'] = 1; if ($this->isForge == false) { if (is_uploaded_file($_FILES[$field]['tmp_name'])) { IFile::mkdir($this->dir); move_uploaded_file($_FILES[$field]['tmp_name'], $this->dir . $fileInfo[0]['name']); } } else { IFile::xcopy($_FILES[$field]['tmp_name'], $this->dir . $fileInfo[0]['name']); } } } } } } $info[$field] = $fileInfo; } return $info; }
/** * @brief 对字符串进行普通的过滤处理 * @param string $str 被过滤的字符串 * @param int $limitLen 限定字符串的字节数 * @return string 被过滤后的字符串 * @note 仅对于部分如:<script,<iframe等标签进行过滤 */ public static function text($str, $limitLen = false) { $str = self::limitLen($str, $limitLen); $str = trim($str); require_once dirname(__FILE__) . "/htmlpurifier-4.3.0/HTMLPurifier.standalone.php"; $cache_dir = hopedir . "templates_c/htmlpurifier/"; if (!file_exists($cache_dir)) { IFile::mkdir($cache_dir); } $config = HTMLPurifier_Config::createDefault(); //配置 允许flash $config->set('HTML.SafeEmbed', true); $config->set('HTML.SafeObject', true); $config->set('Output.FlashCompat', true); //配置 缓存目录 $config->set('Cache.SerializerPath', $cache_dir); //设置cache目录 //允许<a>的target属性 $def = $config->getHTMLDefinition(true); $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top'); $purifier = new HTMLPurifier($config); //过略掉所有<script>,<i?frame>标签的on事件,css的js-expression、import等js行为,a的js-href return $purifier->purify($str); }
function ticket_excel_list() { IFile::mkdir($this->ticketDir); $dirArray = array(); $dirRes = opendir($this->ticketDir); while ($fileName = readdir($dirRes)) { if (!in_array($fileName, IFile::$except)) { $dirArray[$fileName]['name'] = $fileName; $dirArray[$fileName]['size'] = filesize($this->ticketDir . '/' . $fileName); $dirArray[$fileName]['time'] = date('Y-m-d', fileatime($this->ticketDir . '/' . $fileName)); } } $this->dirArray = $dirArray; $this->redirect('ticket_excel_list', false); }
/** * @brief 开始运行 */ public static function run() { set_time_limit(0); ini_set("max_execution_time", 0); $csvType = IReq::get('csvType'); $category = IFilter::act(IReq::get('category'), 'int'); $pluginDir = IWeb::$app->getBasePath() . 'plugins/csvPacketHelper/'; if (!file_exists($pluginDir)) { die('此功能仅供授权版本使用,请您购买商业授权'); } if (!class_exists('ZipArchive')) { die('服务器环境中没有安装zip扩展,无法使用此功能'); } if (extension_loaded('mbstring') == false) { die('服务器环境中没有安装mbstring扩展,无法使用此功能'); } //处理上传 $uploadInstance = new IUpload(9999999, array('zip')); $uploadCsvDir = 'runtime/cvs/' . date('YmdHis'); $uploadInstance->setDir($uploadCsvDir); $result = $uploadInstance->execute(); if (!isset($result['csvPacket'])) { die('请上传指定大小的csv数据包'); } if (($packetData = current($result['csvPacket'])) && $packetData['flag'] != 1) { $message = $uploadInstance->errorMessage($packetData['flag']); die($message); } $zipPath = $packetData['fileSrc']; $zipDir = dirname($zipPath); $imageDir = IWeb::$app->config['upload'] . '/' . date('Y/m/d'); file_exists($imageDir) ? '' : IFile::mkdir($imageDir); //解压缩包 $zipObject = new ZipArchive(); $zipObject->open($zipPath); $isExtract = $zipObject->extractTo($zipDir); $zipObject->close(); if ($isExtract == false) { $message = '解压缩到目录' . $zipDir . '失败!'; die($message); } //实例化商品 $goodsObject = new IModel('goods'); $photoRelationDB = new IModel('goods_photo_relation'); $photoDB = new IModel('goods_photo'); $cateExtendDB = new IModel('category_extend'); //获得配置文件中的数据 $config = new Config("site_config"); $dirHandle = opendir($zipDir); while ($fileName = readdir($dirHandle)) { if (strpos($fileName, '.csv') !== false) { //创建解析对象 switch ($csvType) { case "taobao": include_once $pluginDir . 'taoBaoPacketHelper.php'; $helperInstance = new taoBaoPacketHelper($zipDir . '/' . $fileName, $imageDir); $titleToCols = taoBaoTitleToColsMapping::$mapping; break; default: $message = "请选择csv数据包的格式"; die($message); } //从csv中解析数据 $collectData = $helperInstance->collect(); //插入商品表 foreach ($collectData as $key => $val) { $collectImage = isset($val[$titleToCols['img']]) ? $val[$titleToCols['img']] : ''; //有图片处理 if ($collectImage) { //图片拷贝 $_FILES = array(); foreach ($collectImage as $image) { foreach ($image as $from => $to) { if (!is_file($from)) { continue; } IFile::xcopy($from, $to); //构造$_FILES全局数组 $_FILES[] = array('size' => 100, 'tmp_name' => $to, 'name' => basename($to), 'error' => 0); } } //调用文件上传类 $photoObj = new PhotoUpload(); $uploadImg = $photoObj->run(true); $showImg = current($uploadImg); } //处理商品详情图片 $toDir = IUrl::creatUrl() . dirname($to); $goodsContent = preg_replace("|src=\".*?(?=/contentPic/)|", "src=\"{$toDir}", trim($val[$titleToCols['content']], "'\"")); $insertData = array('name' => IFilter::act(trim($val[$titleToCols['name']], '"\'')), 'goods_no' => goods_class::createGoodsNo(), 'sell_price' => IFilter::act($val[$titleToCols['sell_price']], 'float'), 'market_price' => IFilter::act($val[$titleToCols['sell_price']], 'float'), 'up_time' => ITime::getDateTime(), 'create_time' => ITime::getDateTime(), 'store_nums' => IFilter::act($val[$titleToCols['store_nums']], 'int'), 'content' => IFilter::addSlash($goodsContent), 'img' => isset($showImg['img']) ? $showImg['img'] : '', 'seller_id' => self::$seller_id); $goodsObject->setData($insertData); $goods_id = $goodsObject->add(); //处理商品分类 if ($category) { foreach ($category as $catId) { $cateExtendDB->setData(array('goods_id' => $goods_id, 'category_id' => $catId)); $cateExtendDB->add(); } } //处理商品图片 if ($uploadImg) { $imgArray = array(); foreach ($uploadImg as $temp) { if (isset($temp['img']) && $temp['img']) { $imgArray[] = $temp['img']; } } if ($imgArray) { $photoData = $photoDB->query('img in ("' . join('","', $imgArray) . '")', 'id'); if ($photoData) { foreach ($photoData as $item) { $photoRelationDB->setData(array('goods_id' => $goods_id, 'photo_id' => $item['id'])); $photoRelationDB->add(); } } } } } } } //清理csv文件数据 IFile::rmdir($uploadCsvDir, true); die('<script type="text/javascript">parent.artDialogCallback();</script>'); }
function savesqldata() { $tabelname = IReq::get('tabelname'); $dirname = IReq::get('dirname'); //创建文件夹 IFile::mkdir(hopedir . '/dbbak/' . $dirname); /***获取数据***/ $info = $this->mysql->getarr("show create table `{$tabelname}`"); $sqldata[] = $info['0']['Create Table']; $list = $this->mysql->getarr("select * from " . $tabelname . " limit 0, 20000 "); if (is_array($list)) { foreach ($list as $key => $value) { $keys = array_keys($value); $key = array_map('addslashes', $keys); $key = join('`,`', $key); $keys = "`" . $key . "`"; $vals = array_values($value); $vals = array_map('addslashes', $vals); $vals = join("','", $vals); $vals = "'" . $vals . "'"; $sqldata[] = "INSERT INTO `{$tabelname}`({$keys}) VALUES({$vals})"; } } $configData = var_export($sqldata, true); $configStr = "<?php return {$configData}?>"; $fp = fopen(hopedir . '/dbbak/' . $dirname . '/' . $tabelname . '.php', 'w'); fputs($fp, $configStr); fclose($fp); //保存 建表语句 $this->success('操作成功! '); }
/** * @brief 生成缩略图 * @param string $fileName 生成缩略图的目标文件名 * @param int $width 缩略图的宽度 * @param int $height 缩略图的高度 * @param string $extName 缩略图文件名附加值 * @param string $saveDir 缩略图存储目录 * @return string 缩略图文件名 */ public static function thumb($fileName, $width = 200, $height = 200, $extName = '_thumb', $saveDir = '') { if (is_file($fileName)) { //获取原图信息 list($imgWidth, $imgHeight) = getImageSize($fileName); //计算宽高比例,获取缩略图的宽度和高度 if ($imgWidth >= $imgHeight) { $thumbWidth = $width; $thumbHeight = $width / $imgWidth * $imgHeight; } else { $thumbWidth = $height / $imgHeight * $imgWidth; $thumbHeight = $height; } //生成$fileName文件图片资源 $thumbRes = self::createImageResource($fileName); $thumbBox = imageCreateTrueColor($width, $height); //填充补白 $padColor = imagecolorallocate($thumbBox, 255, 255, 255); imagefilledrectangle($thumbBox, 0, 0, $width, $height, $padColor); //拷贝图像 imagecopyresampled($thumbBox, $thumbRes, ($width - $thumbWidth) / 2, ($height - $thumbHeight) / 2, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); //生成缩略图文件名 $fileExt = IFile::getFileSuffix($fileName); $thumbFileName = str_replace('.' . $fileExt, $extName . '.' . $fileExt, $fileName); //切换目录 if ($saveDir && IFile::mkdir($saveDir)) { $thumbFileName = $saveDir . '/' . basename($thumbFileName); } //生成图片文件 $result = self::createImageFile($thumbBox, $thumbFileName); if ($result == true) { return $thumbFileName; } else { return null; } } else { return null; } }