![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
King of Portal
|
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?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It depends upon the OS. Same would happen if you were doing it from a command line.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
King of Portal
|
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.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#4 |
|
King of Portal
|
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.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Mar 2007
Posts: 33
Rep Power: 0
![]() |
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";
$newname = "bar";
If (file_exists("$oldname") AND !file_exists("$newname"))
{
rename()
} Else {
print "File/Folder not found, or new File/Folder name already exists";
} |
|
|
|
|
|
#6 |
|
King of Portal
|
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.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#7 |
|
Sexy Programmer
|
Is there a function modifier in PHP that makes a function thread-safe?
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#8 |
|
King of Portal
|
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.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Huge arrays in C (game-oriented problem theme) | Rather Generic | C | 6 | Mar 19th, 2006 1:09 AM |
| cgi/perl script + IE problem | joyceshee | Perl | 2 | Jan 24th, 2006 11:10 AM |
| Data logging problem from the serial port | jerryleo | Perl | 0 | Jan 10th, 2006 7:47 AM |
| problem with user defined class mixed with functions | willj729 | C++ | 4 | Oct 9th, 2005 3:26 PM |
| help with recursion problem | the_new_guy_in_town | Java | 3 | Apr 7th, 2005 3:04 AM |