简体   繁体   中英

How to create backup of my directory with password protected zip file in PHP?

I want to create a weekly backup of my project directory in PHP. I need help to create a password protected zip file in php. I use the below function, but that not create a whole folder backup as well as not helping for password protected.

    $path = realpath('');
    $files = glob($path.'*');
    $files = $files[0];
    $password = "test';
    @system('zip -P $password'.$filename.' '.$files);

Using zip command you can try the following.

<?php 
   $path = realpath('');
   $password = "test";
   $zipFileName = "file.zip";
   exec ("zip -r -P {$password} {$zipFileName} {$path}");
?>

-r is added to add all the files recursively.

You can use function system() or exec() to execute the command.

See this post https://unix.stackexchange.com/questions/57013/zip-all-files-in-directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM