// 创建目录(如果不存在)
if (!file_exists($uploadDir)) mkdir($uploadDir, 0777, true);
if (!file_exists($processedDir)) mkdir($processedDir, 0777, true);
// 处理上传的文件
$file = $_FILE
$fileTmp = $file['tmp_name'];
$fileType = $file['type'];
$fileSize = $file['size'];
$fileError = $file['error'];
// 验证文件
if ($fileError !== UPLOAD_ERR_OK) {
$error = "文件上传错误: " . getUploadError($fileError);
} elseif ($fileSize > $maxFileSize) {
$error = "文件太大,最大允许 " . ($maxFileSize / (1024 * 1024)) . "MB";
} elseif (!in_array($fileType, $allowedTypes)) {
$error = "只支持 JPG, PNG 或 GIF 格式的图片";
} else {
// 移动上传的文件
$uploadPath = $uploadDir . $fileName;
if (!move_uploaded_file($fileTmp, $uploadPath)) {
$error = "无法保存上传的文件";
} else {
// 获取图像信息
$imageInfo = getimagesize($uploadPath);
$width = $imageInfo[0];
$height = $imageInfo[1];
$type = $imageInfo['mime'];
下一篇:从来就没有性压抑,只有文化压抑