Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve path of tmpfile()

Tags:

php

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()?

like image 846
Zac Avatar asked Jun 26 '12 17:06

Zac


People also ask

Where does php store temporary files?

php stores all temporary files, that includes uploaded files, in the temporary files directory as specified in the php. ini. Note that for uploads, those files might be removed as soon as the script the file was uploaded to was terminated (so unless you delay that script, you probably won't see the uploaded file).

How to create a temporary file in php?

The tmpfile() function in PHP is an inbuilt function which is used to create a temporary file with a unique name in read-write (w+) mode. The file created using tmpfile() function gets automatically deleted when close using fclose() or when there are no remaining references to the file handle.

What does tmp file return?

Returned value If successful, tmpfile() returns a pointer to the stream associated with the file created. If tmpfile() cannot open the file, it returns a NULL pointer. On normal termination (exit()), these temporary files are removed.


1 Answers

It seems stream_get_meta_data() also works :

$tmpHandle = tmpfile(); $metaDatas = stream_get_meta_data($tmpHandle); $tmpFilename = $metaDatas['uri']; fclose($tmpHandle); 
like image 107
DEY Avatar answered Sep 18 '22 17:09

DEY