Retrieve path of tmpfile()

Php

Php Problem Overview


Quickie...

Is there a way to retrieve the path of a file created by tmpfile()?

Or do I need to do it myself with tempnam()?

Php Solutions


Solution 1 - Php

It seems stream_get_meta_data() also works :

$tmpHandle = tmpfile();
$metaDatas = stream_get_meta_data($tmpHandle);
$tmpFilename = $metaDatas['uri'];
fclose($tmpHandle);

Solution 2 - Php

Like this

$path = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile()))); 
file_put_contents($path, 'hello'); 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZacView Question on Stackoverflow
Solution 1 - PhpDEYView Answer on Stackoverflow
Solution 2 - PhpSilver MoonView Answer on Stackoverflow