修改创建文件的权限、增加Request获取处理过的URI
This commit is contained in:
parent
6403077728
commit
cd65e2a255
|
@ -129,7 +129,7 @@ class Framework
|
||||||
$path = './runtime/session/';
|
$path = './runtime/session/';
|
||||||
}
|
}
|
||||||
if (!is_dir($path)) {
|
if (!is_dir($path)) {
|
||||||
mkdir($path, 0775, true);
|
mkdir($path, 0755, true);
|
||||||
}
|
}
|
||||||
define('SESSION_PATH', $path);
|
define('SESSION_PATH', $path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Create
|
||||||
$configPath = $this->projectPath . 'config/';
|
$configPath = $this->projectPath . 'config/';
|
||||||
$configFile = $configPath . 'config.php';
|
$configFile = $configPath . 'config.php';
|
||||||
if (!is_dir($configPath)) {
|
if (!is_dir($configPath)) {
|
||||||
mkdir($configPath, 0777, true);
|
mkdir($configPath, 0755, true);
|
||||||
}
|
}
|
||||||
if (!file_exists($configFile)) {
|
if (!file_exists($configFile)) {
|
||||||
$content = file_get_contents($this->dir . 'tpl/config/config.tpl');
|
$content = file_get_contents($this->dir . 'tpl/config/config.tpl');
|
||||||
|
@ -78,7 +78,7 @@ class Create
|
||||||
];
|
];
|
||||||
for ($i = 0; $i < count($dirArray); $i++) {
|
for ($i = 0; $i < count($dirArray); $i++) {
|
||||||
if (!is_dir($this->projectPath . $dirArray[$i] . '/')) {
|
if (!is_dir($this->projectPath . $dirArray[$i] . '/')) {
|
||||||
mkdir($this->projectPath . $dirArray[$i] . '/', 0777, true);
|
mkdir($this->projectPath . $dirArray[$i] . '/', 0755, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$controllerFile = $this->projectPath . 'controller/index.php';
|
$controllerFile = $this->projectPath . 'controller/index.php';
|
||||||
|
@ -101,7 +101,7 @@ class Create
|
||||||
if (!file_exists($viewFile)) {
|
if (!file_exists($viewFile)) {
|
||||||
$content = file_get_contents($this->dir . 'tpl/view/index.tpl');
|
$content = file_get_contents($this->dir . 'tpl/view/index.tpl');
|
||||||
if (!is_dir($this->projectPath . 'view/index/')) {
|
if (!is_dir($this->projectPath . 'view/index/')) {
|
||||||
mkdir($this->projectPath . 'view/index/', 0777, true);
|
mkdir($this->projectPath . 'view/index/', 0755, true);
|
||||||
}
|
}
|
||||||
if (!file_put_contents($this->projectPath . 'view/Index/index.html', $content)) {
|
if (!file_put_contents($this->projectPath . 'view/Index/index.html', $content)) {
|
||||||
exit('error -6');
|
exit('error -6');
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace system\extend;
|
namespace top\extend;
|
||||||
|
|
||||||
use top\library\Register;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页类
|
* 分页类
|
||||||
|
@ -11,51 +10,74 @@ use top\library\Register;
|
||||||
class Page
|
class Page
|
||||||
{
|
{
|
||||||
|
|
||||||
// 每页显示记录数
|
/**
|
||||||
public $listRow;
|
* 记录总数
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $total = 0;
|
||||||
|
|
||||||
// 记录总数
|
/**
|
||||||
private $total;
|
* 总页数
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $totalPage = 0;
|
||||||
|
|
||||||
// 总页数
|
/**
|
||||||
private $totalPage;
|
* 当前页码
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $page = 1;
|
||||||
|
|
||||||
// 当前页码
|
/**
|
||||||
public $page;
|
* 开始记录
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $firstRow = 0;
|
||||||
|
|
||||||
public $firstRow;
|
/**
|
||||||
|
* 每页显示记录数
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $listRow = 0;
|
||||||
|
|
||||||
public function __construct($listRow, $total)
|
public function __construct($listRow, $total)
|
||||||
{
|
{
|
||||||
$this->listRow = $listRow;
|
$this->listRow = $listRow;
|
||||||
$this->total = $total;
|
$this->total = $total;
|
||||||
$this->page = (isset($_GET['p']) && $_GET['p']) ? (int)$_GET['p'] : ((isset($_POST['p']) && $_POST['p']) ? (int)$_POST['p'] : 1);
|
$this->page = (isset($_GET['p']) && $_GET['p']) ? (int)$_GET['p'] : ((isset($_POST['p']) && $_POST['p']) ? (int)$_POST['p'] : 1);
|
||||||
|
$this->totalPage = $this->totalPage();
|
||||||
|
$this->firstRow = $this->firstRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算开始记录数
|
||||||
|
* @return float|int
|
||||||
|
*/
|
||||||
private function firstRow()
|
private function firstRow()
|
||||||
{
|
{
|
||||||
return ($this->page - 1) * $this->listRow;
|
return ($this->page - 1) * $this->listRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算总页数
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
private function totalPage()
|
private function totalPage()
|
||||||
{
|
{
|
||||||
return ceil($this->total / $this->listRow);
|
return ceil($this->total / $this->listRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process()
|
/**
|
||||||
{
|
* 获取HTML
|
||||||
$this->totalPage = $this->totalPage();
|
* @return string
|
||||||
$this->firstRow = $this->firstRow();
|
*/
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function html()
|
public function html()
|
||||||
{
|
{
|
||||||
$url = Register::get('Route')->rawUri;
|
$uri = request()->uri(true);
|
||||||
// 链接没有匹配&或?,配置了伪静态也就无所谓了
|
// 链接没有匹配&或?,配置了伪静态也就无所谓了
|
||||||
$html = '<ul>';
|
$html = '<ul>';
|
||||||
for ($i = 1; $i < $this->totalPage + 1; $i++) {
|
for ($i = 1; $i < $this->totalPage + 1; $i++) {
|
||||||
$html .= '<li><a href="' . u($url) . '?p=' . $i . '">' . $i . '</a></li>';
|
$html .= '<li><a href="' . u($uri) . '?p=' . $i . '">' . $i . '</a></li>';
|
||||||
}
|
}
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
return $html;
|
return $html;
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace framework\extend;
|
|
||||||
|
|
||||||
use top\library\Loader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件上传类
|
|
||||||
* @author topnuomi
|
|
||||||
*/
|
|
||||||
class Upload
|
|
||||||
{
|
|
||||||
private static $instance;
|
|
||||||
private static $fileType;
|
|
||||||
private static $dirName;
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
private function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 静态调用时传入保存目录以及文件类型
|
|
||||||
* @param $dirName
|
|
||||||
* @param string $fileType
|
|
||||||
* @return Upload
|
|
||||||
*/
|
|
||||||
public static function init($dirName, $fileType = '')
|
|
||||||
{
|
|
||||||
if (!self::$instance) {
|
|
||||||
self::$instance = new self();
|
|
||||||
}
|
|
||||||
self::$dirName = $dirName;
|
|
||||||
self::$fileType = ($fileType) ? $fileType : ['jpg', 'jpeg', 'png', 'gif', 'JPG', 'JPEG', 'PNG', 'GIF'];
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取错误信息
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function uploadPicture($fileName = '', $width = 0, $height = 0, $waterFile = '')
|
|
||||||
{
|
|
||||||
if (!empty($_FILES)) {
|
|
||||||
$data = [];
|
|
||||||
$picture = Loader::model('Picture');
|
|
||||||
foreach ($_FILES as $k => $v) {
|
|
||||||
$fileParts = pathinfo($v['name']);
|
|
||||||
if (in_array($fileParts['extension'], self::$fileType)) {
|
|
||||||
if (!is_dir(self::$dirName))
|
|
||||||
mkdir(self::$dirName, 0777, true);
|
|
||||||
$targetFile = rtrim(self::$dirName, '/') . '/' . ((!$fileName) ? md5($v['name'] . uniqid()) : $fileName);
|
|
||||||
$filePath = $targetFile . '.' . $fileParts['extension'];
|
|
||||||
$tempFile = $v['tmp_name'];
|
|
||||||
// $type = getimagesize($tempFile)['mime'];
|
|
||||||
if (move_uploaded_file($tempFile, $filePath)) {
|
|
||||||
if ($width && $height) {
|
|
||||||
$filePath = resize_image($filePath, $width, $height);
|
|
||||||
}
|
|
||||||
$hash = md5_file($filePath);
|
|
||||||
$file = $picture->getPictureByHash($hash);
|
|
||||||
if ($file) {
|
|
||||||
@unlink($filePath);
|
|
||||||
$filePath = $file['path'];
|
|
||||||
} else {
|
|
||||||
if ($waterFile) {
|
|
||||||
$water = new Water();
|
|
||||||
$water->waterFile($waterFile);
|
|
||||||
$filePath = $water->handler($filePath);
|
|
||||||
}
|
|
||||||
$picture->insert([
|
|
||||||
'path' => ltrim($filePath, '.'),
|
|
||||||
'hash' => $hash
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$filePath = ltrim($filePath, '.');
|
|
||||||
$data[] = $filePath;
|
|
||||||
} else {
|
|
||||||
$this->error = '上传失败';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->error = '文件类型不被允许';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
$this->error = '请上传文件';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,6 +17,18 @@ class Router
|
||||||
*/
|
*/
|
||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前URI
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $uri = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前原始URI
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $rawUri = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模块
|
* 模块
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -87,6 +99,8 @@ class Router
|
||||||
*/
|
*/
|
||||||
public function handler()
|
public function handler()
|
||||||
{
|
{
|
||||||
|
$this->uri = $this->driver->uri;
|
||||||
|
$this->rawUri = $this->driver->rawUri;
|
||||||
$this->module = $this->driver->module;
|
$this->module = $this->driver->module;
|
||||||
$this->class = $this->driver->class;
|
$this->class = $this->driver->class;
|
||||||
$this->ctrl = $this->driver->ctrl;
|
$this->ctrl = $this->driver->ctrl;
|
||||||
|
|
|
@ -205,7 +205,7 @@ class File implements CacheIfs
|
||||||
private function createCacheDir()
|
private function createCacheDir()
|
||||||
{
|
{
|
||||||
if (!is_dir($this->dir)) {
|
if (!is_dir($this->dir)) {
|
||||||
mkdir($this->dir, 0777, true);
|
mkdir($this->dir, 0755, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,19 @@ class Request
|
||||||
return get_client_ip($type, $client);
|
return get_client_ip($type, $client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前请求的URI
|
||||||
|
* @param bool $raw
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function uri($raw = false)
|
||||||
|
{
|
||||||
|
if ($raw) {
|
||||||
|
return $this->router->rawUri;
|
||||||
|
}
|
||||||
|
return $this->router->uri;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模块名称
|
* 模块名称
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
@ -190,7 +203,7 @@ class Request
|
||||||
* 控制器完整类名
|
* 控制器完整类名
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function classname()
|
public function className()
|
||||||
{
|
{
|
||||||
return $this->router->class;
|
return $this->router->class;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +252,7 @@ class Request
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET数据
|
* GET数据
|
||||||
* @param null $name
|
* @param string $name
|
||||||
* @param array $except
|
* @param array $except
|
||||||
* @param string $filter
|
* @param string $filter
|
||||||
* @return null
|
* @return null
|
||||||
|
@ -251,7 +264,7 @@ class Request
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST数据
|
* POST数据
|
||||||
* @param null $name
|
* @param string $name
|
||||||
* @param array $except
|
* @param array $except
|
||||||
* @param string $filter
|
* @param string $filter
|
||||||
* @return null
|
* @return null
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Top implements TemplateIfs
|
||||||
$compileFileName = $this->config['compileDir'] . md5($filename) . '.php';
|
$compileFileName = $this->config['compileDir'] . md5($filename) . '.php';
|
||||||
if (!file_exists($compileFileName) || DEBUG === true) {
|
if (!file_exists($compileFileName) || DEBUG === true) {
|
||||||
if (!is_dir($this->config['compileDir'])) {
|
if (!is_dir($this->config['compileDir'])) {
|
||||||
mkdir($this->config['compileDir'], 0777, true);
|
mkdir($this->config['compileDir'], 0755, true);
|
||||||
}
|
}
|
||||||
if (isset($this->config['tagLib']) && !empty($this->config['tagLib'])) {
|
if (isset($this->config['tagLib']) && !empty($this->config['tagLib'])) {
|
||||||
foreach ($this->config['tagLib'] as $lib) {
|
foreach ($this->config['tagLib'] as $lib) {
|
||||||
|
|
Loading…
Reference in New Issue