Get the path of tmpfile in php

By | March 14, 2013

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

$path = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile()))); 
file_put_contents($path, 'hello'); 
echo file_get_contents($path);
Last Updated On : 14th March 2013

Leave a Reply

Your email address will not be published. Required fields are marked *