从一个文件夹复制,解密然后使用 PHP 解压缩

Copy from one folder, Decrypt then unzip using PHP

$dir = "/var/www/html/test";
$localDir  = "/home/hell/local/db";
$pass = "123456789";
$method = "aes-256-cbc";


$out = "/home/hell/Downloads/db;


$files = scandir($dir);
if (!empty($files)) {
    foreach ($files as $file) {
        if ($file != '.' && $file != '..') {
            if (substr($file, 0, 11)== date('d-M-Y')) {


                 // code...

                copy(".$dir."/".$file.",".$localDir."/".$file");

                $zipName = basename($localDir."/".$file,".aes").".zip";

                $exec = "openssl ".$method." -d -salt -in ".$localDir."/".$file." -out ".$out.$zipName. " -k ".$pass;




            }

        }
    }
}

我的目标是将 .aes 文件从 /var/www/html/test 复制到 /home/hell/local/db 然后解密,然后解压缩并删除复制的文件及其压缩包。 到目前为止,这是我管理的,代码运行时没有错误,但不会生成要解压缩的存档文件。它不会生成要解压缩的文件。

//function to drop database
system("mysql -h".$servername ." -u" .$username ." -p" .$password ." -e 'DROP DATABASE IF EXISTS $dbname'");


//function to create database 
system("mysql -h".$servername ." -u" .$username ." -p" .$password ." -e 'CREATE DATABASE $dbname'");

$files = scandir($dir, SCANDIR_SORT_DESCENDING);
//$files = "\.(aes|AES)$"
$newest_file = $files[0];

$oldPath = $dir."/".$newest_file;
$newPath = $localDir."/".$newest_file."\n";

shell_exec("cp ".$oldPath." ".$newPath);

// copy('".$dir."/".$newest_file."','".$localDir."/".$newest_file."');
$zipName = basename($localDir."/".$newest_file, ".aes");

exec("openssl ".$method." -d -salt -in ".$localDir."/".$newest_file." -out ".$out.$zipName. " -k ".$pass);

//print $zipName."\n";
//print $out.$zipName."\n";
$sqlName = basename($zipName, ".zip");

system("unzip ".$out.$zipName." -d " .$localDir."/"); 

print $localDir."/".$sqlName."\n";

$sq12 = "mysql -h" .$servername ." -u" .$username ." -p" .$password ." " .$dbname ." < " .$localDir."/".$sqlName;

if(exec($sq12)) {

    //unlink($out);
    exec("rm" .$localDir."*");
}

?>

exec() 或 system() 函数永远不会出错。