Cloud Stack Ninja

In table documentos are the documents stored and in table categorias are the subfolders, first I make a table to see if there are documents, then I consult table g to find out what the subfolders are. I save the result of that query in an array, with a for loop I go through the array to build the path and make the copy from folder documentos to folder copia_seguridad, the error failed to open stream is displayed.

<?php

include('conexion.php');
if (!empty($_GET['copia']) ){
    $consultar1 = mysqli_query($conexion,"SELECT * FROM documentos" );
    $total = mysqli_num_rows($consultar1);
    if($total > 0){
        if (!file_exists("copia_seguridad")) {
                mkdir("copia_seguridad",0777,true);                 
            }
            
        while ( $doct = mysqli_fetch_row($consultar1)){
            $consultar_categoria = mysqli_query($conexion,"SELECT nombreCategoria FROM categorias");
            $subdirectory = mysqli_fetch_array($consultar_categoria);
            $longitud = count($subdirectory);
            for($i=0; $i<$longitud; $i++){
            copy("documentos/$subdirectory[$i]/".$doct[1]."","copia_seguridad/documentos/$subdirectory[$i]/".$doct[1]."");                
            }
        }
        echo  "<script> alert('Copia de Seguridad realizada...'); </script>";
        echo "<script>document.location.href = 'admin.php'; </script>";
    }else{
        echo  "<script> alert('No hay documentos para guardar...'); </script>";
        echo "<script>document.location.href = 'admin.php'; </script>";
    }
}    
?>

error

I tried to change the for to a foreach but the error was displayed again.



Read more here: https://stackoverflow.com/questions/64398745/php-dont-copy-directory-and-subdirectory

Content Attribution

This content was originally published by Ives Andrey Rodriguez Acelas at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: