Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从一个文件夹复制,解密,然后使用PHP解压_Php_Openssl_Unzip_Php 5.6 - Fatal编程技术网

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

从一个文件夹复制,解密,然后使用PHP解压,php,openssl,unzip,php-5.6,Php,Openssl,Unzip,Php 5.6,我的目标是将.aes文件从/var/www/html/test复制到/home/hell/local/db,然后对其进行解密,然后解压缩并删除复制的文件及其zip文件。 到目前为止,这是我所管理的,代码运行时没有出现错误,但不会生成要解压缩的存档文件。它不会生成要解压缩的文件 //删除数据库的函数 $dir = "/var/www/html/test"; $localDir = "/home/hell/local/db"; $pass = "123456789"; $method = "aes

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

//删除数据库的函数
$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;




            }

        }
    }
}
系统(“mysql-h...$servername.-u...$username.-p...$password.-e'DROP DATABASE IF EXISTS$dbname'”); //函数创建数据库 系统(“mysql-h...$servername.-u...$username.-p...$password.-e‘创建数据库$dbname’”); $files=scandir($dir,scandir\u SORT\u DESCENDING); //$files=“\(aes | aes)$” $latest_file=$files[0]; $oldPath=$dir.“/”$newest\u文件; $newPath=$localDir.“/”$newest\u文件。“\n”; shell_exec(“cp”。$oldPath。”“$newPath”); //复制(““$dir.”/“$newest_file.”、“$localDir.”/“$newest_file.”); $zipName=basename($localDir./“$newsts_file,.aes”); exec(“openssl”.$method.-d-salt-in“$localDir./”$newest_file.-out“$out.$zipName.-k”.$pass); //打印$zipName。“\n”; //打印$out.$zipName.“\n”; $sqlName=basename($zipName,.zip”); 系统(“解压“$out.$zipName.”-d“$localDir.”/”; 打印$localDir。“/”$sqlName。“\n”; $sq12=“mysql-h”。$servername.-u”。$username.-p”。$password.“$dbname.”<”$localDir./“$sqlName; if(执行官($sq12)){ //取消链接($out); exec(“rm”。$localDir。“*”); } ?>
exec()或system()函数永远不会出错

//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."*");
}

?>