View Single Post
Old May 29th, 2007, 5:02 PM   #9
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by grimpirate
There is such a function tmpfile. However, using it to do what I want isn't quite so apparent. I'll have to think on it and write back.
It should be trivial, unless I misunderstand your first post. Let's recap, then.
  • You want to create a file, xxx.php, based on the user's interaction with a form.
  • You determine the value of xxx based on when the user accesses the form, and thus, you can have a name collision when two or more users access the form at the same time.
  • Such a name collision will cause the file generated by one user's form interaction to be overwritten with that from another, and this is a bad thing.
Now, rather than opening a file named xxx.php (and potentially overwriting one with the same name), you use tmpfile() to create the file, write the output, and close the file. You then try to rename it to xxx.php. If xxx.php does not exist, this should work; otherwise, you increment xxx, and try again (repeat until successful). Of course, this presupposes that you already have a mechanism in place to keep track of your incrementing three-digit value, but I assumed you'd already coded this, or know how to do so.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote