file('file'); if (!$file || !$file->isValid()) { return jsonResponse(null, '未找到文件或文件无效', 400); } $ext = strtolower($file->getUploadExtension()); if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) { return jsonResponse(null, '仅支持图片文件', 400); } $dir = public_path() . '/upload/images/' . date('Ymd'); if (!is_dir($dir)) { mkdir($dir, 0777, true); } $filename = uniqid() . bin2hex(random_bytes(4)) . '.' . $ext; $path = $dir . '/' . $filename; $file->move($path); $url = '/upload/images/' . date('Ymd') . '/' . $filename; return jsonResponse([ 'url' => $url, 'name' => $file->getUploadName(), ], '上传成功'); } }