How to copy a file from one directory to another with PHP?

0

I have 2 websites on the same linux server, but as is logical, there are different folders, with this code I can copy files within the same domain so to speak. How can I copy a file from one domain to another? and in case I have to use ftp, I can only use sftp.

$fichero = 'ejemplo.txt';
$nuevo_fichero = 'carpeta/ejemplo.txt'; // esta es la carpeta dentro del mismo dominio
//me gustaria poder escribir algo como: /var/www/html/carpetadestino/ejemplo.txt

if (!copy($fichero, $nuevo_fichero)) {
    echo "Error al copiar $fichero...\n";
}
    
asked by Luis Cesar 16.06.2018 в 03:15
source

1 answer

1

If both files are on the same server, the displayed code should work ... Both are in the / www / directory, so just go back in the directories, for example: ../www/carpetaAlaQueQuieraCopiar

    
answered by 16.06.2018 / 14:48
source