批改状态:合格
老师批语:
前端
<?phprequire 'pageData.php';?><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="static/css/style.css"><title>Document</title></head><body><table><caption>课程信息表</caption><thead><tr><th>编号</th><th>名称</th><th>封面</th><th>课程简介</th><th>创建时间</th><th>操作</th></tr></thead><tbody><?php foreach ($lists as $list) : ?><tr><td><?= $list['cou_id'] ?></td><td><?= $list['title'] ?></td><td><img style="width:100px" src="<?= $list['pic'] ?>" alt="课程封面"></td><td><?= $list['info'] ?></td><td><?= date("Y-m-d H-m-s", $list['add_time']) ?></td><td><button>删除</button><button>编辑</button></td></tr><?php endforeach; ?></tbody></table><!-- 生成分页条 --><p><? for ($i = 1; $i <= $pages; $i++) : ?><? $jump = sprintf('?page=%d', $i) ?><? $active = ($i == $page) ? 'active' : '' ?><a class="<?= $active ?>" href="<?= $jump ?>"><?= $i ?></a><? endfor ?></p></body></html>
后端
<?php$pdo = new PDO('mysql:host=localhost;charset=utf8;port=3306;dbname=phpcn','root','');//每页的数据量$pageSize = 8;//当前访问的是第几页$page = $_GET['page'] ?? 1;//偏移量$offset = ($page - 1) * $pageSize;$sql = "SELECT `cou_id`,`title`,`pic`,`info`,`add_time` FROM `mj_course_lists` ORDER BY `cou_id` DESC LIMIT {$offset},{$pageSize}";$lists = $pdo->query($sql)->fetchAll();//获取总页数$sql1 = "SELECT COUNT(`cou_id`) AS `sum` FROM `mj_course_lists`";$total = $pdo->query($sql1)->fetch()['sum'];// var_dump($total);$pages = ceil($total / $pageSize);// var_dump($pages);
1.检查文件格式,是否在规定的格式内
2.用’is_uploaded_file()’来检测文件是否是通过http post方法上传的,而不是系统上的一个文件
3.检查文件大小
<?php/*** 事件委托 请求委托 访问类中不存在的成员方法,会用魔术方法拦截,将请求重定向给或委托给别的对象成员方法* 类处理* 委托是指一个对象转发或者委托一个请求给另一个对象,被委托的一方替原先对象处理请求* 委托比继承更加灵活 父类与子类的关系是固定的,只能单继承,但是请求可以委托给多个对象*///被委托类 数据库查询构造器class Query{//创建pdo对象的唯一实例private static $db;protected $table;protected $field;protected $limit;//private 私有的 阻止此类在外部进行实例化private function __construct(){}static function connect($dsn, $user, $pwd){if (is_null(static::$db)) {static::$db = new pdo($dsn, $user, $pwd);}// return static::$db;return new static; //返回query实例}public function table($table){$this->table = $table;return $this;}public function field($field){$this->field = $field;return $this;}public function limit($limit){$this->limit = $limit;return $this;}public function getSql(){return sprintf('SELECT %s FROM %s LIMIT %d', $this->field, $this->table, $this->limit);}public function select(){return static::$db->query($this->getSql())->fetchAll(PDO::FETCH_ASSOC);}}//委托类class Db{static function __callStatic($name, $arguments){$dsn = 'mysql:host=localhost;charset=utf8;port=3306;dbname=phpcn';$user = 'root';$pwd = '';//获取到被委托的类query实例$q = Query::connect($dsn, $user, $pwd);return call_user_func([$q, $name], ...$arguments);}}//客户端$res = Db::table('mj_course_cat')->field('cat_id,name')->limit(20)->select();var_dump($res);
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号