php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
encryption.php
Go to the documentation of this file.
1<?php
3if (!extension_loaded('zip')) {
4 dl('zip.so');
5}
6
7$name = __DIR__ . '/encrypted.zip';
8$pass = 'secret';
9$file = 'foo.php';
10
11echo "== Create with per file password\n";
12
14$zip->open($name, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
15$zip->addFile(__FILE__, $file);
16$zip->setEncryptionName($file, ZipArchive::EM_AES_256, $pass);
17$zip->close();
18
19echo "== Create with global password\n";
20
21$zip = new ZipArchive;
22$zip->open($name, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
23$zip->setPassword($pass);
24$zip->addFile(__FILE__, $file);
25$zip->setEncryptionName($file, ZipArchive::EM_AES_256);
26$zip->close();
27
28echo "== Stat\n";
29
30$zip->open($name);
31print_r($zip->statName($file));
32
33echo "== Read\n";
34
35$zip->setPassword($pass);
36$text = $zip->getFromName($file);
37printf("Size = %d\n", strlen($text));
38$zip->close();
39
40echo "== Stream with context\n";
41
43 'zip' => array(
44 'password' => $pass
45 )
46));
47$text = file_get_contents("zip://$name#$file", false, $ctx);
48printf("Size = %d\n", strlen($text));
stream_context_create(?array $options=null, ?array $params=null)
file_get_contents(string $filename, bool $use_include_path=false, $context=null, int $offset=0, ?int $length=null)
printf(string $format, mixed ... $values)
print_r(mixed $value, bool $return=false)
const int OVERWRITE
const int EM_AES_256
$zip
Definition create.php:8
dl(string $extension_filename)
Definition dl.stub.php:3
$pass
Definition encryption.php:8
$ctx
$file
Definition encryption.php:9
$text
error_reporting(?int $error_level=null)
strlen(string $string)
extension_loaded(string $extension)
#define E_ALL
Definition zend_errors.h:43