cbh Posted March 19, 2007 Share Posted March 19, 2007 My PHP application produces and displays a report in HTML. It also produces a text file version of the same report which will be used as the "Printable Version" if the user wants that. The text version will always have the same name, say STAFF.TXT My question is how do I avoid one user's STAFF.TXT of the file being overwritten by another user's STAFF.TXT ? Link to comment https://forums.phpfreaks.com/topic/43326-avoiding-overwriting-temporary-files/ Share on other sites More sharing options...
Kasuke_Akira Posted March 19, 2007 Share Posted March 19, 2007 Have your php script add directories and create the new .txt file in that user's directory. Seems the most logical as there is no way to stop a file from overwriting one with the same name in the same directory. Link to comment https://forums.phpfreaks.com/topic/43326-avoiding-overwriting-temporary-files/#findComment-210379 Share on other sites More sharing options...
cbh Posted March 19, 2007 Author Share Posted March 19, 2007 Thanks for that reply Kasuke_Akira Users of this web site are anonymous so there's no way I can tell one from the other, and therefore I can make directories or folders for them to store the file. Link to comment https://forums.phpfreaks.com/topic/43326-avoiding-overwriting-temporary-files/#findComment-210402 Share on other sites More sharing options...
nitch Posted March 19, 2007 Share Posted March 19, 2007 well you could add a counter to the end of the filename. Such as STAFF1.txt,STAFF2.txt and increase the counter everytime you create a file. Seems like you could end up with a large amount of txt files being created though. I don't know how temporary these files are but a solution to this would be to store the file info in the database with a timestamp and delete any entries that are over a certain age. Link to comment https://forums.phpfreaks.com/topic/43326-avoiding-overwriting-temporary-files/#findComment-210405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.