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.
The optimum method to rewrite files
Moderator: General Moderators
Re: The optimum method to rewrite files
anyone....?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: The optimum method to rewrite files
Regardless of which way you do it, the web server user will have to have write permissions to the original file. So for portability I would use #1.jateeq wrote: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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.