【问题标题】:Copy from one folder, Decrypt then unzip using PHP从一个文件夹复制,解密然后使用 PHP 解压缩
【发布时间】:2019-01-13 03:04:43
【问题描述】:

$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 > 然后解密它,然后解压缩并删除复制的文件及其 zip。 到目前为止,这就是我所管理的,代码运行时没有错误,但不会生成要解压缩的存档文件。它不会生成要解压缩的文件。

【问题讨论】:

    标签: php openssl unzip php-5.6


    【解决方案1】:
    //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() 函数永远不会出错。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2010-09-05
      • 1970-01-01
      • 2015-12-26
      • 2010-12-14
      • 2011-11-01
      • 1970-01-01
      相关资源
      最近更新 更多