Jump to content

The tempnam function


Heero

Recommended Posts

Hi all,

 

I am having troubling understanding something with the tempnam function.

 

Given this code:

 

<?php
$tmpfname = tempnam("/tmp", "FOO");

$handle = fopen($tmpfname, "w");
fwrite($handle, "writing to tempfile");
fclose($handle);

// do here something

unlink($tmpfname);
?> 

 

I expected the code to create an unique file name in the /tmp directory (this directory already exists) of the current location of my file running it.  However, the code produced a file in the location C:\WINDOWS\FOOB5.tmp.  Which is apparently where my "system's temporary directory" is...I was looking at the phpinfo() results and I couldn't find any reference to this system temporary directory.

 

Could someone enlighten me on why it is placing the unique file in the system temporary directory and not the /tmp directory?

Link to comment
Share on other sites

If the system can't create the file in the directory you specify, it will fall back to a default.  You might want to try "C:\\tmp" as your directory, if that's where you want to make your temporary files.  The webserver must have access to write there, but if it can write to c:\windows then it can write anywhere :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.