prepare("INSERT INTO movie_photos (movie_id, photo_path) VALUES (?, ?)"); $stmt->execute([$movie_id, 'uploads/photos/' . $filename]); } } // 海报 URL function posterUrl($path) { if ($path && file_exists(ROOT_DIR . '/' . $path)) { return '/' . $path; } return '/assets/placeholder-poster.jpg'; } // ===== 头像处理 ===== function getAvatarUrl($avatar_path, $name = '') { if ($avatar_path && file_exists(ROOT_DIR . '/' . $avatar_path)) { return '/' . $avatar_path; } if (!empty($name)) { $letter = mb_substr($name, 0, 1, 'UTF-8'); $colors = ['#e74c3c','#e67e22','#f1c40f','#2ecc71','#3498db','#9b59b6','#1abc9c','#e84393','#00b894','#0984e3']; $color = $colors[abs(crc32($name)) % count($colors)]; return "data:image/svg+xml," . urlencode("{$letter}"); } return '/assets/default-avatar.png'; } // ===== 保存 Base64 图片 ===== function saveBase64Image($base64_data, $save_dir, $prefix = 'avatar') { if (strpos($base64_data, 'base64,') !== false) { $base64_data = substr($base64_data, strpos($base64_data, 'base64,') + 7); } $binary = base64_decode($base64_data); if ($binary === false) return false; $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_buffer($finfo, $binary); finfo_close($finfo); $ext_map = [ 'image/jpeg' => 'jpg', 'image/png' => 'png', 'image/gif' => 'gif', 'image/webp' => 'webp' ]; if (!isset($ext_map[$mime])) return false; $ext = $ext_map[$mime]; $filename = date('YmdHis') . '_' . uniqid() . '_' . $prefix . '.' . $ext; $filepath = $save_dir . $filename; if (file_put_contents($filepath, $binary) === false) return false; return str_replace(ROOT_DIR . '/', '', $filepath); }