The optimum method to rewrite files
Posted: Mon Mar 08, 2010 2:12 pm
Hello,
I have a web interface that allows users to upload files. If the user uploads an already existing file, I want that file to overwrite the existing file. As I see it, there a lot of different ways to do this, but since I haven't done this before, i wanted to pick more experienced programmers' opinion(s).
I know of the following ways, and currently I am going with #4, and in my opinion this is the best because it's simple and reliable :
1: use php's copy() function - although there's something about rewrite failing if the new and old files do not belong to the same owner...
2: open existing file for writing, open uploaded file for reading, copy/paste contents of latter to former (i guess the copy() function already does this)
3: delete existing file, mv uploaded file in its place
4: use linux's native command 'cp'.
Thank you for your time,
Jawad.
I have a web interface that allows users to upload files. If the user uploads an already existing file, I want that file to overwrite the existing file. As I see it, there a lot of different ways to do this, but since I haven't done this before, i wanted to pick more experienced programmers' opinion(s).
I know of the following ways, and currently I am going with #4, and in my opinion this is the best because it's simple and reliable :
1: use php's copy() function - although there's something about rewrite failing if the new and old files do not belong to the same owner...
2: open existing file for writing, open uploaded file for reading, copy/paste contents of latter to former (i guess the copy() function already does this)
3: delete existing file, mv uploaded file in its place
4: use linux's native command 'cp'.
Thank you for your time,
Jawad.