Monday 24 September 2018

PHP: Get the path of tmpfile

tmpfile is a very handy function to create temporary files. It returns the file handle/resource. If the path of the file is needed, for use with file_put_contents for example then here is a quick trick to do that
1
2
3
$path = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
file_put_contents($path, 'hello');
echo file_get_contents($path);

0 comments:

Post a Comment