PHP将文件夹从ftp上的其他位置复制到新目标

PHP将文件夹从ftp上的其他位置复制到新目标,php,mysql,Php,Mysql,我已经使这个脚本生成3个文件夹与随机名称,并在最后,我粘贴一个完整的文件夹,我已经放置在ftp的另一个地方 它真的很适合文件夹,但我不能使副本粘贴到最终文件夹 你能解释一下怎么修吗 <?php $tags = mysqli_query($conn, "SELECT domaine FROM `domains` ORDER BY rand() LIMIT 1; ") or die(mysqli_error($conn)); while($row = mys

我已经使这个脚本生成3个文件夹与随机名称,并在最后,我粘贴一个完整的文件夹,我已经放置在ftp的另一个地方

它真的很适合文件夹,但我不能使副本粘贴到最终文件夹

你能解释一下怎么修吗

     <?php $tags = mysqli_query($conn, "SELECT domaine FROM `domains` ORDER BY rand() LIMIT 1; ") or die(mysqli_error($conn));
             while($row = mysqli_fetch_array($tags)) 
                         {            
                             $domainresul =  $row['domaine'];
                         } 

                            function random_string($length) {
                                $key = '';
                                $keys = array_merge(range(0, 9), range('a', 'z'));
                                for ($i = 0; $i < $length; $i++) {
                                $key .= $keys[array_rand($keys)];
                                }

                                return $key;
                            }


                            $file = "index.php";
                            $content = $sideindhold;


                            if (isset($_POST['submit'])) {


                            $ftp_server = "xxx"; // virtuelt doamin
                            $conn_id = ftp_connect($ftp_server);
                            $ftp_user_name = "xxx"; // bruger jeg har opsat på min xampp, med rettigheder til example.com
                            $ftp_user_pass = "xxx";
                            $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

                            // $root="url/phptest";
                            $root = $domainresul;




                            /* **************************************** */
                            /* create a stream context telling PHP to overwrite the file */
                            $options = array('ftp' => array('overwrite' => true));
                            $stream = stream_context_create($options);
                            /* **************************************** */


                            // check connection
                            echo "<center>";
                            if ((!$conn_id) || (!$login_result)) {
                            echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">';
                            echo "FTP connection has failed!";
                            echo "Attempted to connect to <b>$ftp_server</b> for user <b>$ftp_user_name</b>";
                            echo '</div>';
                            } else {

                            $foldername1 = random_string(4);
                            $foldername2 = random_string(3);
                            $foldername3 = random_string(2);



                            $directory = "$root/$foldername1";

                            if (ftp_mkdir($conn_id, $directory)) {

                            $directory = "$root/$foldername1/$foldername2";

                            if (ftp_mkdir($conn_id, $directory)) {

                            $directory = "$root/$foldername1/$foldername2/$foldername3";


                            if (ftp_mkdir($conn_id, $directory)) {
                            /* **************************************** */
                            /* and finally, put the contents */
                            $hostname2 = "ftp://" . $ftp_user_name . ":" . $ftp_user_pass . "@" . $ftp_server . "/";
                 $hostname = "ftp://" . $ftp_user_name . ":" . $ftp_user_pass . "@" . $ftp_server . "/" . $directory . "/";


                   $src = $hostname2 . "xxx.xxx/se";
                   $dst = $hostname;

                   echo $src;
                   echo $dst;

                   shell_exec("cp -r $src $dest");

                 /* **************************************** */

             }
         }
     } else {
         echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px">';
         echo "Could not create directory: <b>$directory</b>";
         echo '</div>';
     }
 }
 echo "</center>";  } ?>


您是否尝试过
cp-R
?即使用大写字母
R
。我假设您在Linux上,它非常区分大小写。当我尝试时,它会显示echo“Array”。。这与
cp-R
建议无关,所以在此之前您必须有一个错误。再加入几个echo语句(
echo 1;
echo 2;
等),查看错误发生的位置。如果它回显
Array
,则您正在打印一个包含数组的变量。你需要找出哪个
echo
语句在做这件事。我现在已经找到了!我的脚本工作是创建随机文件夹名,并找到用于文件销毁的korrekt位置。但是它不会复制文件夹并将其放在新url的末尾。您是否尝试更改
cp-R
命令?