0

I need a lot of help! I would make the code below, I copied the folder along with the files inside it to the folder "Backup_Archives" ie in the folder uploads will have:

uploads/a1/arq.pdf
uploads/a2/arq2.pdf

So the Backup folder will be after copying:

Backup_Archives/a1 /arq.pdf
Backup_Archives/a2/arq2.pdf

I would like the folders / files to be copied and after the copy is done, delete all the files inside the subfolders, such as:

uploads/a1/ "arq.pdf"
uploads/a2/ "arq2.pdf"

CODE:

<?php
    // pega a lista de arquivos com a extensão pdf.
    $list = glob(__dir__.'/uploads/a1/*.pdf');

    // diretorio aonde serão remanejados. 
    $save = __dir__.'/uploads/Backup_Arquivos/';
        echo 'Nenhum arquivo será movido caso nenhuma mensagem abaixo apareça!<br>';
    foreach ($list as $value) {
        if (rename($value, $save.basename($value))) {
            echo '<br>Item da Enviado com êxito! <br>';
        }
    }
?>

Note: My code is only moving the files from a folder to the Backup_Files folder.

Thank you!

JeanTdz
  • 1
  • 2

1 Answers1

1

You are moving files not copying

bool rename ( string old_name, string new_name [, resource context])

bool copy ( string source, string dest)

bool unlink ( string filename, resource context)

So in your case, you don't have to delete the files.

If you want to copy and then delete the file

should look like this

<?php
// pega a lista de arquivos com a extensão pdf.
$list = glob(__dir__.'/uploads/a1/*.pdf');

// diretorio aonde serão remanejados.
$save = __dir__.'/uploads/Backup_Arquivos/';
echo 'Nenhum arquivo será movido caso nenhuma mensagem abaixo apareça!<br>';
foreach ($list as $value) {
    if (copy($value, $save.basename($value))) {
        echo '<br>Item da Enviado com êxito! <br>';
        unlink($value);
    }
}
?>