Search code examples
phpajaxfiledirectorycopy

PHP copy + overwrite dialog per file


I'm developing a system in PHP + AJAX that could copy files from one folder on the server to another folder in the server.

My question is when I try to copy a folder to another one that already have some files with the same name inside of it.

In this case, I want to show a popup to the user in order to confirm if he wants to overwrite EACH one of this files.

How could I do that? How can I wait for the response of the user to each dialog after starting the copy?

By the way, is it better to use the cp command of linux or is it better to do this using unlink and rmdir of PHP?


Solution

  • I think you should divide the process into several parts:

    1. Check for colliding files.
    2. If some colliding files exist, list them to the user and ask for confirmation (dialog).
    3. If there's no collision, or if the user confirm he agrees to overwrite destination files, copy the files.

    If you want to ask for each one of this files, ask a confirmation per file (a dialog box with checkboxes, or several dialog boxes). Once the user has confirm (or not) every overwriting, copy the files.