Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Determine filename of tmpfile() (http://www.programmingforums.org/showthread.php?t=14955)

grimpirate Jan 16th, 2008 11:12 AM

Determine filename of tmpfile()
 
Is there any way possible to determine the filename of a file created by the function tmpfile()?
On the PHP site they show you a way to determine the path to the temporary folder but how do I obtain the filename (assuming that's even possible)?
The fstat() function doesn't seem to yield anything about the filename. Any ideas?

Sane Jan 16th, 2008 11:37 AM

Re: Determine filename of tmpfile()
 
What if there is more than one temp file, how are you even deciding which one to choose?

mbd Jan 16th, 2008 1:17 PM

Re: Determine filename of tmpfile()
 
if you need to know the name of the tempfile, you should use the tempnam function to get the name of a unique file, then fopen it.

Sane Jan 16th, 2008 1:25 PM

Re: Determine filename of tmpfile()
 
I think grimpirate is referring to this as a continuation of his "flock" thread. He needs to know how to recall the name of the temporary file from a new PHP instance. I think?

Could you clarify, grimpirate? :)

grimpirate Jan 16th, 2008 4:07 PM

Re: Determine filename of tmpfile()
 
You're absolutely right Sane I couldn't determine which file it is that is being created I mean the only thing I can tell is that the file starts with a prefix of 'php', then some hex characters, and the extension '.tmp'. But if more than one is created how would I know which one it is? I was stating that as an aside regarding my train of thought/advancements (which isn't anything really). I agree with what mbd is saying in the sense that tempnam() does return the unique filename to me. However, tmpfile() has one explicit condition which is that it's removed in case of an abnormal script failure. With tempnam() I imagine I would have to code some sort of register_shutdown_function() and I'm not entirely sure how I would deal with errors and such in there (should they transpire). With tmpfile() I'm more comfortable in saying that since it is a hard-coded aspect of the php language the file would definitely be removed.

grimpirate Jan 18th, 2008 1:48 PM

Re: Determine filename of tmpfile()
 
Figured it out: you use the stream_get_meta_data() function and then access the 'uri' key in the output array


All times are GMT -5. The time now is 10:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC