How to replace a file with another file of same name which has new content in PHP?
I am new to PH开发者_JS百科P. In my application user when clicks for PDF, a copy on his name will be stored in a server. Next time, when he wants another PDF of different data, even that also will be stored on the same name in the server. I want to replace the old copy with the new PDF. Please tell me how to solve it. Thank You.
Use copy($source, $dest)
and the destination will always be overwritten if it exists.
See: http://www.php.net/manual/en/function.copy.php
Billy Moon's answer will work, but you can also use file_put_contents()
and file_get_contents()
.
Heres how one might do that:
file_put_contents('user_file_new.pdf', file_get_contents('user_file_old.pdf'));
精彩评论