The tempnam function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FCC
Forum Newbie
Posts: 2
Joined: Wed Apr 25, 2007 1:47 am

The tempnam function

Post by FCC »

Hi all,

I am having troubling understanding something with the tempnam function.

Given this code:

Code: Select all

<?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?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

"/tmp" refers to a folder named "tmp" in the filesystem's root directory (c:\). If the folder is in the same directory as your script, you can reference it with "./tmp". Otherwise, make an absolute reference to the directory (c:/path/to/tmp).
Post Reply