基于 OIDC 认证的 PHP 文件上传系统,支持多种文件类型上传,提供友好的用户界面。
usr/upload/{年}/{月}/{毫秒时间戳}.{扩展名}重要提示:为了保护敏感信息,项目中包含 config.php.example 示例配置文件。请勿将实际的 config.php 文件提交到版本控制系统。
复制示例配置文件:
cp config.php.example config.php
编辑 config.php 文件,填入真实的配置信息
所有配置项均位于 config.php 文件中,主要包含三个配置区块:
$siteConfig = [
"title" => "您的网站标题", // 网站标题
"login_title" => "登录 - 您的网站标题", // 登录页标题
"site_url" => "https://your-domain.com/", // 网站URL
"app_name" => "您的应用名称", // 应用名称
"max_file_size" => 10 * 1024 * 1024, // 最大文件大小(字节)
];
$uploadConfig = [
"max_file_size" => 10 * 1024 * 1024, // 最大文件大小(字节)
"max_file_size_mb" => 10, // 最大文件大小(MB,用于显示)
"upload_dir" => "usr/upload", // 上传目录
"allowed_types" => [ // 允许的MIME类型
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
"application/pdf",
"text/plain",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
],
"allowed_extensions" => [ // 允许的文件扩展名
"jpg", "jpeg", "png", "gif", "webp",
"pdf", "txt", "doc", "docx", "xls", "xlsx",
],
"image_extensions" => [ // 图片扩展名(用于预览)
"jpg", "jpeg", "png", "gif", "webp",
],
"max_display_files" => 10, // 文件列表最大显示数量
];
$oidcConfig = [
"issuer" => "https://your-oidc-provider.com/api/v1/authorize/your-client-id/oidc", // OIDC提供商URL
"client_id" => "YOUR_CLIENT_ID", // 客户端ID(必填)
"client_secret" => "YOUR_CLIENT_SECRET", // 客户端密钥(必填)
"redirect_uri" => "https://your-domain.com/index.php", // 回调地址
"scope" => "openid profile email", // 权限范围
"response_type" => "code", // 响应类型
"state" => "random_state_string", // 状态参数
"timeout" => 10, // HTTP请求超时时间(秒)
];
easy-images/ ├── .gitignore # Git忽略文件配置 ├── config.php.example # 配置文件示例(脱敏) ├── config.php # 配置文件(实际使用,需要从示例复制) ├── index.php # 主程序文件 ├── README.md # 说明文档 └── usr/ # 上传文件根目录 └── upload/ # 上传文件存储目录 └── {年}/ # 按年分类 └── {月}/ # 按月分类 └── {毫秒时间戳}.{扩展名}
usr/upload/ 目录可写config.php.example 为 config.phpsiteConfig 中的网站信息oidcConfig 中的 OIDC 认证参数(client_id 和 client_secret 必填)uploadConfig 中的上传配置访问系统首页,点击 "OIDC 登录" 按钮,跳转到 OIDC 提供商进行身份验证。
上传成功后,文件会显示在列表中,点击图片缩略图可查看大图。
保护配置文件:
config.php 提交到版本控制系统.gitignore 忽略敏感配置文件修改默认配置:更新 config.php 中的 OIDC client_id 和 client_secret
使用 HTTPS:确保在生产环境使用 HTTPS 协议
设置正确的权限:
定期清理:定期清理不需要的上传文件
备份重要文件:定期备份上传的文件
随机生成 state:在生产环境中应动态生成 state 参数以防止 CSRF 攻击
config.php 文件包含了系统的所有配置项,各配置区块的详细说明请参考文件内的注释。修改配置后无需重启服务,配置会立即生效。
usr/upload/ 目录是否有写入权限config.php 中的 OIDC 配置是否正确config.php 文件