app/models/Media.php
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
require_once __DIR__ . '/../../core/BaseModel.php';
class Media extends BaseModel {
protected $table = 'media';
protected $fillable = ['filename', 'filepath', 'filesize', 'mimetype', 'width', 'height', 'alt', 'title', 'user_id'];
public function getAllMedia($page = 1, $perPage = PER_PAGE, $type = null) {
$where = "1=1";
$params = [];
if ($type) {
switch ($type) {
case 'image':
$where .= " AND mimetype LIKE 'image/%'";
break;
case 'video':
$where .= " AND mimetype LIKE 'video/%'";
break;
case 'audio':
$where .= " AND mimetype LIKE 'audio/%'";
break;
case 'document':
$where .= " AND (mimetype LIKE 'application/%' OR mimetype LIKE 'text/%')";
break;
}
}
return $this->paginate($page, $perPage, $where, $params, 'created_at', 'DESC');
}
public function getMediaWithUser($id) {
$sql = "SELECT m.*, u.username as uploader_name
FROM {$this->table} m
LEFT JOIN users u ON m.user_id = u.id
WHERE m.id = ?";
return $this->db->fetchOne($sql, [$id]);
}
public function getRecentMedia($limit = 10) {
$sql = "SELECT * FROM {$this->table} ORDER BY created_at DESC LIMIT ?";
return $this->db->fetchAll($sql, [$limit]);
}
public function getImages($limit = 20) {
$sql = "SELECT * FROM {$this->table} WHERE mimetype LIKE 'image/%' ORDER BY created_at DESC LIMIT ?";
return $this->db->fetchAll($sql, [$limit]);
}
public function getVideos($limit = 20) {
$sql = "SELECT * FROM {$this->table} WHERE mimetype LIKE 'video/%' ORDER BY created_at DESC LIMIT ?";
return $this->db->fetchAll($sql, [$limit]);
}
public function getAudio($limit = 20) {
$sql = "SELECT * FROM {$this->table} WHERE mimetype LIKE 'audio/%' ORDER BY created_at DESC LIMIT ?";
return $this->db->fetchAll($sql, [$limit]);
}
public function search($keyword, $page = 1, $perPage = PER_PAGE) {
后面还有 43 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
