ok, thanks guys, I got it to work using
$tmpfname = tempnam("c:/windows/temp", "FOO");
but I had to remove the line
unlink($tmpfname);
I looked up the function but don't really understand what it does.
what is the purpose of unlink($tmpfname);
here is what my code looks like now, it works and saves the file.
$tmpfname = tempnam("d:/moby", "FOO.txt");
$handle = fopen($tmpfname, "w");
fwrite($handle, "writing to tempfile");
fclose($handle);
// do here something
//unlink($tmpfname);
Thanks