![]() |
rename() problem
I'm using the rename function and its behavior seems to vary dependent on the server. On my home computer when I use rename() and the new filename already exists it throws an error. However, on the server if the new filename is the same as the old filename it just overwrites the old file. Any suggestions how to work around this or fix this?
|
It depends upon the OS. Same would happen if you were doing it from a command line.
|
Yeah I read up on the PHP and apparently it only occurs on Windows systems where rename fails (I'm running XP). I was kind of banking on that feature. I'm thinking I can use an fopen() function with the 'x' parameter to create the file and then just add the data.
|
That actually worked beautifully. Even better than the rename function because I don't have to create a temporary file beforehand. Unfortunately, it means I also had to increase the php version requirement of my script from 4.3.0 to 4.3.2. Such is technology.
|
Alternatively, you could have done some checking first. (of course, you would probably check a lot more, so you could get the exact message required).
:
$oldname = "foo"; |
Yeah I actually thought about that tAK but the problem is that since PHP can run multiple requests at one time I'm not sure that doing that would be "thread safe." If two processes were running at that very same moment doing that procedure it's possible (though slim) that they could overlap and thus one file might overwrite the other. I figure that fopen is safer in its usage because its coded that way.
|
Is there a function modifier in PHP that makes a function thread-safe?
|
Not that I know of, they have an flock function but it isn't respected in all cases. The parameter I'll be using in fopen is 'x' which creates a file but if it already exists it produces an error. I figure the code for one function has to finish executing before another function can execute so this is my safest bet.
|
| All times are GMT -5. The time now is 12:42 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC