public function run(&$content) { if (!file_exist(UPLOAD_PATH . 'install.lock')) { return true; } $data = S('common_behavior_hooks'); if (!$data) { $hooks = M('hooks')->where(array('status' => 1))->getField('name, addons'); foreach ($hooks as $key => $value) { if ($value) { $map['status'] = 1; $names = explode(',', $value); $map['name'] = array('IN', $names); $data = M('addons')->where($map)->getField('id, name'); if ($data) { $addons = array_intersect($names, $data); Hook::add($key, array_map('get_addon_class', $addons)); } } } S('common_behavior_hooks', Hook::get()); } else { Hook::import($data, false); } }
public function run(&$params) { if (MODULE_NAME == 'Install') { return true; } else { //自动安装判断 if (!file_exist(UPLOAD_PATH . 'install.lock')) { redirect(U('Install/Index/index')); exit; } } if (!S('common_behavior_setting')) { $setting_db = M('setting'); $list = $setting_db->getField('name,value,type', true); S('common_behavior_setting', $list); } else { $list = S('common_behavior_setting'); } //使用自定义设置 if (is_array($list) && !empty($list)) { foreach ($list as $name => $config) { switch (strtolower($config['type'])) { //数组类型 case 'array': $config['value'] = explode(',', $config['value']); break; } C($name, $config['value']); } } }
/** * 安装验证 */ public function _initialize() { $this->lock_file = './Public/tmp/install.lock'; if (!APP_DEBUG && file_exist($this->lock_file)) { $this->show('对您已经安装过,请不要重复安装!', 'utf-8'); exit; } }
function reMakeCondition($saveDirAndFile, $reMakeTime = -1) { if ($reMakeTime == -1) { if (file_exist($saveDirAndFile)) { return true; } } elseif (file_exists($saveDirAndFile) && time() - filemtime($saveDirAndFile) > $reMakeTime) { return true; } return false; }
function khtml() { foreach ($this->modules as $module) { $mod = KHTML_CLASS_DIR . "/" . $mod . "_khtml.class.php"; if (!file_exist($mod)) { die("module not found: {$module}: {$mod}"); } include_once $mod; } $this->khtml .= "<html><head>%HEAD% %CSS% %JS%</head><body>%BODY%</body></html>"; }
public function index($debug = '') { if ($debug) { file_delete(UPLOAD_PATH . 'install.lock'); } $status = array('status' => 1, 'url' => U('Index/step1')); if (file_exist(UPLOAD_PATH . 'install.lock')) { $status = array('status' => 0, 'url' => U('/'), 'msg' => '已经成功安装了,请不要重复安装!'); } $this->assign('status', $status); $this->display(); }
/** * 删除文件 */ public function delete($filename) { $filename = urldecode($filename); $filename = ltrim($filename, '/'); $filename = preg_replace("/\\.+/", '.', $filename); //屏蔽非法路径 $filename = UPLOAD_PATH . $filename; if (file_exist($filename)) { if (file_delete($filename)) { $this->success('操作成功'); } } $this->error('操作失败'); }
public function run(&$params) { if (MODULE_NAME == 'Install') { return true; } else { //自动安装判断 $lock_file = './Public/tmp/install.lock'; if (!file_exist($lock_file)) { redirect(U('Install/index/index')); exit; } } if (!S('common_setting_behavior')) { $setting_db = M('setting'); $list = $setting_db->getField('key,value', true); S('common_setting_behavior', $list); } else { $list = S('common_setting_behavior'); } //使用自定义设置 if (is_array($list) && !empty($list)) { foreach ($list as $key => $value) { switch ($key) { //上传类型过滤 case 'FILE_UPLOAD_CONFIG.exts': case 'FILE_UPLOAD_LINK_CONFIG.exts': case 'FILE_UPLOAD_IMG_CONFIG.exts': case 'FILE_UPLOAD_FLASH_CONFIG.exts': case 'FILE_UPLOAD_MEDIA_CONFIG.exts': if (!is_array($value)) { $value = explode(',', $value); } break; } C($key, $value); } } }
/** * xml转数组 * @param string $xml * @param bool $isFile * @return null|array */ function xml2array($xml, $isFile = false) { if ($isFile && file_exist($xml)) { $xml = file_read($xml); } $xml = @simplexml_load_string($xml); if (is_object($xml)) { $xml = json_encode($xml); $xml = @json_decode($xml, true); } if (!is_array($xml)) { return null; } return $xml; }
/** * 文章导入 */ public function import_news($catid, $filename = '') { if (IS_POST) { //过滤特殊字符,防止非法下载文件 $filename = str_replace(array('.', '/', '\\'), '', $filename); $filename = UPLOAD_PATH . 'import/' . $filename . '.data'; if (!file_exist($filename)) { $this->error('导入失败'); } $content = file_read($filename); //解密 try { $data = gzinflate(base64_decode($content)); } catch (\Exception $e) { } if (!isset($data)) { file_delete($filename); $this->error('非法数据'); } //防止非法数据 try { $data = json_decode($data, true); } catch (\Exception $e) { } if (!is_array($data) || !isset($data['type']) || $data['type'] != 'news' || !isset($data['verify']) || !isset($data['data'])) { file_delete($filename); $this->error('非法数据'); } if ($data['verify'] != md5(var_export($data['data'], true) . $data['type'])) { file_delete($filename); $this->error('非法数据'); } $news_db = M('news'); //开始导入 asort($data['data']); foreach ($data['data'] as $add) { unset($add['id']); $add['catid'] = $catid; $news_db->add($add); } file_delete($filename); $this->success('导入成功'); } else { $this->error('非法访问'); } }
/** * 栏目导入 */ public function categoryImport($filename = '') { if (IS_POST) { //过滤特殊字符,防止非法下载文件 $filename = str_replace(array('.', '/', '\\'), '', $filename); $filename = UPLOAD_PATH . 'import/' . $filename . '.data'; if (!file_exist($filename)) { $this->error('导入失败'); } $content = file_read($filename); //解密 try { $data = gzinflate(base64_decode($content)); } catch (\Exception $e) { } if (!isset($data)) { file_delete($filename); $this->error('非法数据'); } //防止非法数据 try { $data = json_decode($data, true); } catch (\Exception $e) { } if (!is_array($data) || !isset($data['type']) || $data['type'] != 'category' || !isset($data['verify']) || !isset($data['data'])) { file_delete($filename); $this->error('非法数据'); } if ($data['verify'] != md5(var_export($data['data'], true) . $data['type'])) { file_delete($filename); $this->error('非法数据'); } $category_db = D('Category'); //先清空数据再导入 $category_db->where('catid > 0')->delete(); $category_db->clearCatche(); //开始导入 asort($data['data']); foreach ($data['data'] as $add) { $category_db->add($add); } file_delete($filename); $this->success('导入成功'); } else { $this->error('非法访问'); } }
/** * 添加水印 * @param string $image * @return bool */ private function water($image) { if (!C('IMAGE_WATER_CONFIG.status')) { return false; } if (!C('IMAGE_WATER_CONFIG.image')) { return false; } $image = UPLOAD_PATH . $image; $config = C('TMPL_PARSE_STRING'); $water = str_replace($config[UPLOAD_PATH], UPLOAD_PATH, C('IMAGE_WATER_CONFIG.image')); if (!file_exist($image)) { return false; } if (!file_exist($water)) { return false; } $imagick = new ImageMagick(); $imagick->read(file_read($image)); $imagick->add_watermark(file_read($water), 10, 10, false); return file_write($image, $imagick->get_content()); }
<?php $dir = $_REQUEST['dirname']; $name = $_REQUEST['newname']; $filename = $dir . '/' . $name; $filenamenew = $filename; $i = 1; while (file_exist($filenamenew)) { $i = $i + 1; $filenamenew = $filename . '($i)'; } echo fopen($filenamenew . '/html', "w"); // create ?>
/** * 删除文件 */ public function fileDelete($filename) { $filename = urldecode($filename); $filename = $this->fileBathPath . $filename; if (file_exist($filename)) { if (file_delete($filename)) { $this->success('操作成功'); } } $this->error('操作失败'); }
<?php // when expecting an integer, cast it to one $_GET['id'] = (int) $_GET['id']; // if you MUST allow a user to specify the // page validate the page meticulously. $page = basename($_GET['page']); if (!preg_match('!^[A-Za-z0-9_]+$!', $page) || !@file_exist("template/{$page}.php")) { exit; } // Do not assume automatic validation features // are always enabled. if (!get_magic_quotes_gpc()) { foreach ($_GET as $key => $val) { $_GET[$key] = addslashes($val); } }
public function upFile($sId) { $mId = 's_' . $sId; $path = C('IMG_PATH'); $src = base64_decode($_POST['pic']); $pic1 = base64_decode($_POST['pic1']); $pic2 = base64_decode($_POST['pic2']); $pic3 = base64_decode($_POST['pic3']); if ($src) { $ext = $this->getPicExt($src); $filenameSrc = $mId . "_src."; $filename170 = $mId . "_big."; $filename130 = $mId . "_middle."; $filename20 = $mId . "_small."; if (file_exist($path . $filenameSrc . 'png')) { unlink($path . $filenameSrc . 'png'); } if (file_exist($path . $filename170 . 'png')) { unlink($path . $filename170 . 'png'); } if (file_exist($path . $filename130 . 'png')) { unlink($path . $filename130 . 'png'); } if (file_exist($path . $filename20 . 'png')) { unlink($path . $filename20 . 'png'); } file_put_contents($path . $filenameSrc . $ext, $src); file_put_contents($path . $filename170 . $ext, $pic1); file_put_contents($path . $filename130 . $ext, $pic2); file_put_contents($path . $filename20 . $ext, $pic3); $imgType = array('_src', '_big', '_middle', '_small'); switch ($ext) { case 'jpg': foreach ($imgType as $type) { $pathStr = $path . $mId . $type; $src = $pathStr . '.jpg'; $image = ImageCreateFromJPEG($src); $output = $pathStr . '.png'; imagepng($image, $output); imagedestroy($image); unlink($src); } break; case 'gif': foreach ($imgType as $type) { $pathStr = $path . $mId . $type; $src = $pathStr . '.gif'; $image = ImageCreateFromJPEG($src); $output = $pathStr . '.png'; imagepng($image, $output); imagedestroy($image); unlink($src); } break; case 'bmp': foreach ($imgType as $type) { $pathStr = $path . $mId . $type; $src = $pathStr . '.bmp'; $image = ImageCreateFromJPEG($src); $output = $pathStr . '.png'; imagepng($image, $output); imagedestroy($image); unlink($src); } break; } $imgArr['srcPic'] = 'upload/' . $filenameSrc . 'png'; $imgArr['bigPic'] = 'upload/' . $filename170 . 'png'; $imgArr['middlePic'] = 'upload/' . $filename130 . 'png'; $imgArr['smallPic'] = 'upload/' . $filename20 . 'png'; $student_db = D('MemberInfo'); if ($student_db->where(array('member_id' => $sId))->save(array('head_photo' => json_encode($imgArr)))) { $rs['status'] = 1; echo json_encode($rs); exit; } $rs['status'] = 0; } $rs['status'] = 1; echo json_encode($rs); exit; }
/** * 添加水印图片 * @param array $config */ public function waterImage(array $config = array()) { $config = array_merge($this->water, $config); if (!$config['status']) { return false; } if (file_exist($config['image'])) { $watermark = $this->imagine->open($config['image']); //本地水印图片 } else { $path = C('TMPL_PARSE_STRING'); $file = str_replace($path[UPLOAD_PATH], UPLOAD_PATH, $config['image']); if (!file_exist($file)) { return false; } $waterImage = file_read($file); $watermark = $this->imagine->load($waterImage); //水印图片 } $water = $watermark->getSize(); //水印图片尺寸 $position = $this->getPosition($water->getWidth(), $water->getHeight(), $config['position'], $config['x'], $config['y']); //如果水印不能完整显示,则不添加水印 list($width, $height) = $this->getSize(); if ($water->getWidth() + $position->getX() > $width) { return false; } if ($water->getHeight() + $position->getY() > $height) { return false; } $format = $this->getFormat(); if ($this->lib != 'gd' && strtolower($format) == 'gif') { $this->image->layers()->coalesce(); foreach ($this->image->layers() as $frame) { $frame->paste($watermark, $position); } } else { $this->image->paste($watermark, $position); } }
var cron_jobs_count=' . $n . ' var cron_jobs=new Array('; for ($i = 0; $i < $n; $i++) { $error = EMPTY_STRING; $current_cron_job = $cron_jobs[$i]; $cron_job = explode(COMMA, $current_cron_job); $n = sizeof($cron_job); if ($n > 1) { $cron_jobs_job = $cron_job[0]; $pos = strpos($cron_jobs_job, '?'); if ($pos !== false) { $cron_jobs_task = $cron_jobs_job; } else { $cron_jobs_task = substr($cron_jobs_job, 0, $pos - 1); } if (file_exist($cron_jobs_task)) { $schedule_days = EMPTY_STRING; if ($n > 2) { $time_index = 2; $schedule_days = strtolower($cron_job[1]); $schedule_days_array = explode(SLASH, $schedule_days); for ($j = 0, $m = sizeof($schedule_days_array); $j < $m; $j++) { if ($schedule_days) { $schedule_days .= COMMA; } $schedule_days .= array_search($schedule_days_array[$j], $week_days); } } else { $time_index = 1; } $schedule_days .= RPAREN;