type === Type::FILES && $emptyUploadUrl && $emptyFileData) { throw new LucentException("No file data submitted"); } elseif ($schema->type !== Type::FILES && !($emptyUploadUrl && $emptyFileData)) { throw new LucentException("You can't upload a file to a regular record"); } elseif ($schema->type !== Type::FILES) { return new FileUploadResult( recordFile: null, duplicateId: "", isDuplicate: false ); } if (!$emptyUploadUrl) { $file = self::uploadFileFromUrl($uploadFromUrl); return uploadFile($schema, $file); } return new FileUploadResult( recordFile: File::fromArray($file), duplicateId: "", isDuplicate: false ); } /** * @throws LucentException */ private static function uploadFileFromUrl(string $url): UploadedFile { $pathinfo = pathinfo($url); $contents = file_get_contents($url); if ($contents === false) { throw new LucentException("Failed to upload file from url"); } $file = '/tmp/' . $pathinfo['basename']; file_put_contents($file, $contents); return new UploadedFile($file, $pathinfo['basename']); } }