getExtensionFromMimeType($mimeType); $fileName = $fileName ?? uniqid('file_', true); $fullFileName = "{$fileName}.{$extension}"; $tempPath = sys_get_temp_dir() . '/' . $fullFileName; if (file_put_contents($tempPath, $fileContent) === false) { throw new RuntimeException('Failed to create temporary file'); } return new UploadedFile( $tempPath, $fullFileName, $mimeType, null, true ); } /** * Get file extension from mime type * * @param string $mimeType * @return string */ private function getExtensionFromMimeType(string $mimeType): string { $mimeToExt = [ 'image/jpeg' => 'jpg', 'image/png' => 'png', 'image/gif' => 'gif', 'application/pdf' => 'pdf', 'text/plain' => 'txt', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', 'application/vnd.ms-excel' => 'xls', ]; return $mimeToExt[$mimeType] ?? 'bin'; } }