public static function text($str) { $config = HTMLPurifier_Config::createDefault(); $cache_dir = Tiny::getPath('cache') . "/htmlpurifier/"; if (!file_exists($cache_dir)) { File::mkdir($cache_dir); } $config = HTMLPurifier_Config::createDefault(); //配置 缓存目录 $config->set('Cache.SerializerPath', $cache_dir); //设置cache目录 //配置 允许flash $config->set('HTML.SafeEmbed', true); $config->set('HTML.SafeObject', true); $config->set('Output.FlashCompat', true); //$config->set('HTML.Allowed', 'p'); //$config->set('AutoFormat.AutoParagraph', true); //$config->set('AutoFormat.RemoveEmpty', true); //允许<a>的target属性 $def = $config->getHTMLDefinition(true); $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top'); $purifier = new HTMLPurifier($config); if (get_magic_quotes_gpc()) { $str = stripslashes($str); $str = $purifier->purify($str); $str = addslashes($str); } else { $str = $purifier->purify($str); } return self::sql($str); }
/** * 构造初始化 * * @access public * @param mixed $fieldName * @param string $uploadPath * @param string $size * @param string $types * @param string $nameType * @param string $nameId */ public function __construct($fieldName, $uploadPath = "", $size = '500k', $types = '', $nameType = 'date', $nameId = '') { if (isset($_FILES[$fieldName])) { $this->files = $_FILES[$fieldName]; if ($uploadPath == '') { $this->uploadPath = Tiny::getPath('uploads'); } else { $this->uploadPath = $uploadPath; } $endchar = strtolower(substr($size, -1)); if ($endchar == 'k') { $this->size = substr($size, 0, -1) << 10; } else { if ($endchar == 'm') { $this->size = substr($size, 0, -1) << 20; } else { $this->size = intval($size); } } if ($types != '') { $this->types = ",{$types},"; } $this->nameType = $nameType; $this->fileNameId = $nameId; } }
/** * 备份 * * @access public * @param array $tables * @param mixed $file_name * @return mixed */ public function back($tables = array(), $file_name = null) { //$model = new Model(); $sql = ""; foreach ($tables as $table) { $row = $this->db->doSql("show create table `{$table}` "); $sql .= "DROP TABLE IF EXISTS `" . $row[0]['Table'] . "`;\n"; $sql .= $row[0]['Create Table'] . ";\n"; $rows = $this->db->doSql("select * from `{$table}`"); if (count($rows) > 0) { $sql .= 'INSERT INTO `' . $table . '` (`'; $fields = (array) current($rows); $keys = array_keys($fields); $sql .= implode("`,`", $keys) . "`) VALUES "; foreach ($rows as $row) { $values = array_values($row); foreach ($values as $key => $value) { $values[$key] = mysql_real_escape_string($value); } $sql .= "('" . implode("','", $values) . "'),"; } $sql = rtrim($sql, ","); $sql .= ";\n"; } } if ($file_name == null) { $file_name = date('YmdH') . '_' . rand(1000, 9999) . '_' . rand(1000, 9999) . '.sql'; } $database_path = Tiny::getPath('database') . $file_name; $file = new File($database_path, 'w+'); return $file->write($sql); }
function photoshop_upload() { $file = $_FILES['upfile']; if ($file['error'] == 4) { $msg = array('error', '请选择文件后再上传!'); $this->redirect("photoshop", true, array('msg' => $msg)); } else { if ($file['error'] == 1) { $msg = array('error', '文件超出了php.ini文件指定大小!'); $this->redirect("photoshop", true, array('msg' => $msg)); } else { if ($file['size'] > 0) { $key = md5_file($file['tmp_name']); $gallery = new Model('gallery'); $img = $gallery->where("`key`='" . $key . "'")->find(); echo JS::import('dialog?skin=brief'); echo JS::import('dialogtools'); if (!$img) { $upfile_path = Tiny::getPath("uploads"); $upfile_url = preg_replace("|^" . APP_URL . "|", '', Tiny::getPath("uploads_url")); $upfile = new UploadFile('upfile', $upfile_path, '10m'); $upfile->save(); $info = $upfile->getInfo(); $result = array(); if ($info[0]['status'] == 1) { $url = $upfile_url . $info[0]['path']; $key = md5_file($upfile_path . $info[0]['path']); $type = Req::args("type") == null ? 0 : intval(Req::args('type')); $gallery->data(array('key' => $key, 'type' => $type, 'img' => $url))->save(); echo "<script>art.dialog.opener.setImg('{$url}');</script>"; } else { $msg = array('error', $info[0]['msg']); $this->msg = $msg; $this->redirect("photoshop", false); } } else { $url = $img['img']; echo "<script>art.dialog.opener.setImg('{$url}');</script>"; } } } } exit; }
public function upload_head() { $upfile_path = Tiny::getPath("uploads") . "/head/"; $upfile_url = preg_replace("|" . APP_URL . "|", '', Tiny::getPath("uploads_url") . "head/", 1); //$upfile_url = strtr(Tiny::getPath("uploads_url")."head/",APP_URL,''); $upfile = new UploadFile('imgFile', $upfile_path, '500k', '', 'hash', $this->user['id']); $upfile->save(); $info = $upfile->getInfo(); $result = array(); if ($info[0]['status'] == 1) { $result = array('error' => 0, 'url' => $upfile_url . $info[0]['path']); $image_url = $upfile_url . $info[0]['path']; $image = new Image(); $image->suffix = ''; $image->thumb(APP_ROOT . $image_url, 100, 100); $model = new Model('user'); $model->data(array('head_pic' => $image_url))->where("id=" . $this->user['id'])->update(); $safebox = Safebox::getInstance(); $user = $this->user; $user['head_pic'] = $image_url; $safebox->set('user', $user); } else { $result = array('error' => 1, 'message' => $info[0]['msg']); } echo JSON::encode($result); }