Я решил перезвонить немного.
multiple
при добавлении дополнительных опций
// objects as value/desc
let selectValues = {
"1": "test 1",
"2": "test 2",
"3": "test 3",
"4": "test Four"
};
//use div here as using "select" mucks up the original selected value in "mySelect"
let opts = $("<div />");
let opt = {};
$.each(selectValues, function(value, desc) {
opts.append($('<option />').prop("value", value).text(desc));
});
opts.find("option").appendTo('#mySelect');
// array of objects called "options" in an object
let selectValuesNew = {
options: [{
value: "1",
description: "2test 1"
},
{
value: "2",
description: "2test 2",
selected: true
},
{
value: "3",
description: "2test 3"
},
{
value: "4",
description: "2test Four"
}
]
};
//use div here as using "select" mucks up the original selected value
let opts2 = $("<div />");
let opt2 = {}; //only append after adding all options
$.map(selectValuesNew.options, function(val, index) {
opts2.append($('<option />')
.prop("value", val.value)
.prop("selected", val.selected)
.text(val.description));
});
opts2.find("option").appendTo('#mySelectNew');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="mySelect">
<option value="" selected="selected">empty</option>
</select>
<select id="mySelectNew" multiple="multiple">
<option value="" selected="selected">2empty</option>
</select>
If you are using PHP 5.2 or later, you could use the Zip Library
and then do something along the lines of:
$images_dir = '/path/to/images';
//this folder must be writeable by the server
$backup = '/path/to/backup';
$zip_file = $backup.'/backup.zip';
if ($handle = opendir($images_dir))
{
$zip = new ZipArchive();
if ($zip->open($zip_file, ZipArchive::CREATE)!==TRUE)
{
exit("cannot open <$zip_file>\n");
}
while (false !== ($file = readdir($handle)))
{
$zip->addFile($images_dir.'/'.$file);
echo "$file\n";
}
closedir($handle);
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
echo 'Zip File:'.$zip_file . "\n";
}
Вы можете легко сжать папку с помощью этой команды:
tar -cvzpf backup.tar.gz /path/to/folder
Эту команду можно запустить через phps system () - function.
Не забудьте экранировать все команды.