F
F
felony13twelve2020-05-21 05:37:52
PHP
felony13twelve, 2020-05-21 05:37:52

How to move a folder with files and folders to another folder?

Good morning everyone! I have this code

$old_dir = 'test/gg'; 
 $new_dir = 'kl/gg'; 
 
 mkdir($new_dir, 0755); 
 $dir = opendir($old_dir); 
 while($file = readdir($dir)) 
 { 
 if(is_file($old_dir."/".$file)) 
 { 
 $cont = file_get_contents($old_dir."/".$file); 
 file_put_contents($new_dir."/".$file, $cont); 
 } 
 }

The joke is that it only creates a folder, but it does not transfer files and folders, used copy, it still does not help.

I used several codes that I found on the Internet, they used copy but they still only transfer files too.

Does anyone have their own function? I will be grateful for your function :)

Here is the code from the Internet
# Папка с файлами
$old_dir = './kap/';
 
# Папка в которую перемещаем
$new_dir = './bridun/';
 
$dir=opendir($old_dir);
$i=1;
while (false !== ($file = readdir($dir))) {
    if (is_file($old_dir.$file ) && $file[0] != '...') 

  {
        if (!file_exists($new_dir.$file[0])) {
            #Создаём папку по первому символу от названия
           mkdir($new_dir.$file[0], 0755); #0777
       }
        copy($old_dir.$file, $new_dir.$file[0].'./'.$file);
    }
    #Ограничиваем за один раз
   if ($i==500) break;
    $i++;
}
closedir($dir);


As I wrote at the top that it does not transfer folders, only files

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question