I have a really simple question, but I can't find any docs to connect the dots. How do PHP functions actually use managed file objects?

I am successfully uploading a file and getting the managed file object ($file->uri is something like "temporary://filename.xml").

<?php
  $file
= file_load($file_id);
?>

Now, though, I want to use DOMDocument::load ( string $filename ) or DOMDocument::loadxml ( string $xmldata ).

So, how do I get $filename or $xmldata? What's the best "Drupal way" to do this?

drupal_realpath( $file ) looks like it will get me a file name that I can use, but the docs say that it's deprecated. So, what am I supposed to use? The docs say " the vast majority of the PHP functions work perfectly with streams", but don't actually say what a stream is or how to give it to such a function.

Comments

For the first case you can

For the first case you can use

$file = file_load($file_id);
DOMDocument::load ($file->uri) ;

For the second you would want
$file = file_load($file_id);
$xmldata = file_get_contents($file->uri);
DOMDocument::loadxml ($xmldata);
nobody click here