Jump to content

Questions about the tempnam() function...


clonetrooper9494

Recommended Posts

Questions about the tempnam() function...Alright, I am currently switching hosts, and on the other site, I ask my self the following questions about the tempnam() function:

1. If you create a temp file, does it appear on your site so other people can write in it and read it?2. A temp file gets deleted after the page is left where it was created at, so does the file get unlinked becuase one person left, or stay there becuase the both people haven't left?3. If a temp file is named the same as a real file, and the person leaves the page, does the real file get deleted too, or are just the recent changes?

If you have ever used the tempnam() function, please answer some of my questions... or if you want, try them out so we can both learn something!

Link to comment
Share on other sites

1. If you create a temp file, does it appear on your site so other people can write in it and read it?
It gets created in a directory you specify, or the system temp directory if yours isn't available. It gets created with permissions 0600, which lets the file owner read and write and denies permissions to everyone else. The file owner is the process that runs PHP, on a Windows machine it is the anonymous internet user account.
2. A temp file gets deleted after the page is left where it was created at, so does the file get unlinked becuase one person left, or stay there becuase the both people haven't left?
When execution for person 1 ends, file 1 gets deleted. When the execution for person 2 ends, file 2 gets deleted. They don't use the same files.
3. If a temp file is named the same as a real file, and the person leaves the page, does the real file get deleted too, or are just the recent changes?
There aren't "temp" files and "real" files, there are only files. You can't use this function to create a file with the name of a file that already exists:
tempnam — Create file with unique file name
Link to comment
Share on other sites

Well, I was trying to have a php 'chat', where the page would be called 'http://somewhere.com/chat/bob123_and_john123.php' and both bob123 and john123 can see and post info...I guess the real question is is there a way to unlink a file when a user leaves a page? I guess I didn't need to ask Q. 2... With this chat, I would need it when one of the people leave, that page, it wouldn't stay there until bob123 and john123 started another chat.

Link to comment
Share on other sites

Thats what I was afraid of... I saw a site with a game on it and it asked you if you wanted to leave... I don't know how to do that though...I might be able to find a way so if they nagivate off the page, it reidects them back (like a loop)... :):mellow::):wub: ... until they manually unlink it of courseI am looking into that....

Link to comment
Share on other sites

Thats what I was afraid of... I saw a site with a game on it and it asked you if you wanted to leave... I don't know how to do that though...
You can use JavaScript with the window.onunload event which fires when the user leaves the page.
Link to comment
Share on other sites

Umm... I was reading the AJAX tutorial on the W3 site, and I didn't understand it at all, I was just trying to find a way to activate a PHP function using JS/AJAX... :) Would it work if I had it open a frame befor the page left with a short line of PHP that would unlink the file? or would the page unload befor the iframe would load?I am moving this question to the JS boards soon... check over there!

Link to comment
Share on other sites

Umm... I was reading the AJAX tutorial on the W3 site, and I didn't understand it at all, I was just trying to find a way to activate a PHP function using JS/AJAX... :) Would it work if I had it open a frame befor the page left with a short line of PHP that would unlink the file? or would the page unload befor the iframe would load?I am moving this question to the JS boards soon... check over there!
The idea is to use AJAX to start another PHP page, that only has the purpose of deleting such a user file. You won't be writing PHP code with JavaScript. Infact, if you do that, you're practically just begging for your chat application to be hacked (imagine person A writing as if it's person B, deleting person A after he's done, or worse yet, delete your whole chat application altogether). What you're doing is sending an "invisible" request to another web page, the PHP page, which does the job.
Link to comment
Share on other sites

NEVER allow third parties to write server-side code. Or else unlink(/) will leave you not very happy.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...