How to replace a file with another file of the same name that has new content in PHP?


I am new to PHP. 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.