zipからダウンロード

set_time_limit(0);

$zip_name = 'create_zip_'.date('Ymd').'.zip';
$zip_tmp_dir = dirname(__FILE__).'/tmp_zip/'; 

$zip_obj = new ZipArchive();

$result = $zip_obj -> open($zip_tmp_dir.$zip_name, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if(!$result){
    echo 'error code : '.$result;
    exit();
}

$files[] = [
	'zip_path' => 'building.jpg',
	'file_path' =>  dirname(__FILE__)."/".'building.jpg'
];

foreach ($files as $file)
{
    //ファイルを追加する場合
    $zip_obj -> addFile($file['file_path'], $file['zip_path']);
}

$zip_obj -> addFromString('test.txt', 'test');
$zip_obj -> close();

header('Content-Type: application/force-download;');
header('Content-Length: '.filesize($zip_tmp_dir.$zip_name));
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_tmp_dir.$zip_name);

$files[] = [
	'zip_path' => ['building.jpg', 'monkey.jpg'],
	'file_path' =>  ['building.jpg', 'monkey.jpg']
];

foreach ($files as $file)
{
    //ファイルを追加する場合
    $zip_obj -> addFile( dirname(__FILE__)."/".$file['file_path'], $file['zip_path']);
}

[Sun Apr 7 16:33:50 2019] PHP Notice: Undefined index: /home/vagrant/local/app/test/file_path in /home/vagrant/local/app/test/index.php on line 24
[Sun Apr 7 16:33:50 2019] PHP Warning: ZipArchive::addFile() expects parameter 2 to be string, array given in /home/vagrant/local/app/test/index.php on line 24

うん、まー要するに配列で渡せば、zipで複数ダウンロードできるってわけね。
チェックボックスなら、POSTで対象ファイルを渡せばOK

phpのzip機能

Check if PHP has Zip extension

[vagrant@localhost test]$ php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

うん、ありますね。

phpでファイルダウンロード

$file_name = "building.jpg";
$file_path = dirname(__FILE__)."/".$file_name;

$download_file_name = "building.jpg";

header('Content-Type: application/force-download;');
header('Content-Length: '.filesize($file_path));
header('Content-Disposition: attachment; filename="'.$file_name.'"');

readfile($download_file_name);

特に問題なし

うーん、複数のファイルをDLしたいです。

Config::Simple

Config::Simple – 簡単な設定ファイルクラス

use Config::Simple;
Config::Simple->import_from(‘app.ini’, \%Config);
$cfg = new Config::Simple(‘app.ini’);
$user = $cfg->param(‘User’);
%Config = $cfg->vars();
$cfg->param(‘User’, ‘sherzodR’);
$cfg->param(‘Users’, [‘sherzodR’, ‘geek’, ‘merlyn’]);
$cfg->param(-block=>’last-access’, -value=>{‘time’=>time()});
$mysql = $cfg->param(-block=>’mysql’);
$cfg->save();

Perl Scalars

Perl has three basic data types: scalars, scalar arrays, and scalar associative arrays. In this context, scalar data refers to simple data such as numbers and strings. Also, as an essential element of programming, there is the concept of variables. Variables are “value containers” that are used to temporarily store various values.
In Perl, there are three variables, scalar variable, array, and associative array respectively, in the form corresponding to each data type, and the scalar variable is the most basic one among them, and stores numerical value and character string can do.
Scalar variable names can start with $ (dollar) + one alphabetic character, and can use numbers, alphabetic characters and underscores thereafter. Also, because it is cause sensitive, $ a and $ A, for example, are treated as different things.

OK
$abc123
$abc_123

NG
$123abc
$abc-123

mysqldumpでテーブルをバックアップ

command

$ mysqldump -u root -p db table --single-transaction > hoge.dump

test

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| items          |
| name           |
| news           |
| user           |
+----------------+
4 rows in set (0.00 sec)

[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test items > /tmp/dump/items.sql
Enter password:

ほーーーーーーー

複数テーブルの場合
[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test items name > /tmp/dump/some.dump
Enter password:

テーブルを複数並べればいいだけ。

オプション
–skip-lock-tables
–lock-tablesオプションを無効にする。–optが–lock-tablesを有効にするので、それを打ち消す為に使用する。

なるほどーーーーーー

mysqldump

Use mysqldump command to backup / resotre MySQL database. The mysqldump command is included with MySQL installation.

Will explain two backup method.
1. How to back up only specific databases
2. How to back up all databases

To dump backup data from a specific MySQL database, use the following command:

$ mysqldump --single-transaction -u username -p DBname > output destination file name

やってみます。
mysql> mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump’ at line 1

あれ?????? これ、mysqlにログインしなくていいのかな。
[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump
Enter password:
[vagrant@localhost ~]$

ほう、そういうことか。。

次はテーブルのバックアップもやりたいね。

空チェックをして型チェック

nullかチェックをして、その後、型チェックを行う

$var = "2019/04/01";

if(empty($var)){
	echo "値を入力してください";
} else{
	if(preg_match("/^[a-zA-Z0-9]+$", $var)){
		echo "英数字で入力してください";
	} else {
		echo "合格";
	}
}

うむ、nullかどうかはオブジェクトにしたいですな。

netstat -anl

[vagrant@localhost test]$ php -S 192.168.35.10:8000
[Fri Apr 5 08:52:04 2019] Failed to listen on 192.168.35.10:8000 (reason: Address already in use)

netstat -anl

[vagrant@localhost test]$ netstat -anl
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.35.10:8000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:37780 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 64 192.168.35.10:22 192.168.35.1:54547 ESTABLISHED
tcp 0 0 192.168.35.10:22 192.168.35.1:54544 ESTABLISHED
tcp 0 3520 192.168.35.10:22 192.168.35.1:50521 ESTABLISHED
tcp 0 0 192.168.35.10:22 192.168.35.1:51478 ESTABLISHED
tcp 0 0 192.168.35.10:22 192.168.35.1:51485 ESTABLISHED
tcp 0 0 192.168.35.10:8000 192.168.35.1:54691 TIME_WAIT
tcp 0 0 192.168.35.10:8000 192.168.35.1:54692 TIME_WAIT
tcp 0 0 ::1:25 :::* LISTEN
tcp 0 0 :::443 :::* LISTEN
tcp 0 0 :::3306 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::8080 :::* LISTEN
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::39668 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:42054 0.0.0.0:*
udp 0 0 127.0.0.1:967 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:944 0.0.0.0:*
udp 0 0 :::33848 :::*
udp 0 0 :::56935 :::*
udp 0 0 :::5353 :::*
udp 0 0 :::111 :::*
udp 0 0 :::944 :::*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 13 [ ] DGRAM 8502 /dev/log
unix 2 [ ACC ] STREAM LISTENING 11210 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 6744 @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 11270 private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 11274 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 11278 private/bounce
unix 2 [ ACC ] STREAM LISTENING 11282 private/defer
unix 2 [ ACC ] STREAM LISTENING 11286 private/trace
unix 2 [ ACC ] STREAM LISTENING 11290 private/verify
unix 2 [ ACC ] STREAM LISTENING 11294 public/flush
unix 2 [ ACC ] STREAM LISTENING 11298 private/proxymap
unix 2 [ ACC ] STREAM LISTENING 11302 private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 11306 private/smtp
unix 2 [ ACC ] STREAM LISTENING 11310 private/relay
unix 2 [ ACC ] STREAM LISTENING 11314 public/showq
unix 2 [ ACC ] STREAM LISTENING 11318 private/error
unix 2 [ ACC ] STREAM LISTENING 11322 private/retry
unix 2 [ ACC ] STREAM LISTENING 11326 private/discard
unix 2 [ ACC ] STREAM LISTENING 11330 private/local
unix 2 [ ACC ] STREAM LISTENING 11334 private/virtual
unix 2 [ ACC ] STREAM LISTENING 11338 private/lmtp
unix 2 [ ACC ] STREAM LISTENING 11342 private/anvil
unix 2 [ ACC ] STREAM LISTENING 11346 private/scache
unix 2 [ ] DGRAM 7122 @/org/kernel/udev/udevd
unix 2 [ ACC ] STREAM LISTENING 9985 /var/lib/mysql/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 8580 /var/run/rpcbind.sock
unix 3 [ ] STREAM CONNECTED 72333
unix 3 [ ] STREAM CONNECTED 72332
unix 2 [ ] DGRAM 72329
unix 3 [ ] STREAM CONNECTED 72251
unix 3 [ ] STREAM CONNECTED 72250
unix 2 [ ] DGRAM 72247
unix 2 [ ] DGRAM 71574
unix 3 [ ] STREAM CONNECTED 66767
unix 3 [ ] STREAM CONNECTED 66766
unix 2 [ ] DGRAM 66763
unix 3 [ ] STREAM CONNECTED 63845
unix 3 [ ] STREAM CONNECTED 63844
unix 2 [ ] DGRAM 63841
unix 3 [ ] STREAM CONNECTED 63730
unix 3 [ ] STREAM CONNECTED 63729
unix 2 [ ] DGRAM 63726
unix 2 [ ] DGRAM 40479
unix 2 [ ] STREAM CONNECTED 18047
unix 2 [ ] STREAM CONNECTED 16398
unix 2 [ ] DGRAM 12216
unix 2 [ ] DGRAM 11375
unix 3 [ ] STREAM CONNECTED 11349
unix 3 [ ] STREAM CONNECTED 11348
unix 3 [ ] STREAM CONNECTED 11345
unix 3 [ ] STREAM CONNECTED 11344
unix 3 [ ] STREAM CONNECTED 11341
unix 3 [ ] STREAM CONNECTED 11340
unix 3 [ ] STREAM CONNECTED 11337
unix 3 [ ] STREAM CONNECTED 11336
unix 3 [ ] STREAM CONNECTED 11333
unix 3 [ ] STREAM CONNECTED 11332
unix 3 [ ] STREAM CONNECTED 11329
unix 3 [ ] STREAM CONNECTED 11328
unix 3 [ ] STREAM CONNECTED 11325
unix 3 [ ] STREAM CONNECTED 11324
unix 3 [ ] STREAM CONNECTED 11321
unix 3 [ ] STREAM CONNECTED 11320
unix 3 [ ] STREAM CONNECTED 11317
unix 3 [ ] STREAM CONNECTED 11316
unix 3 [ ] STREAM CONNECTED 11313
unix 3 [ ] STREAM CONNECTED 11312
unix 3 [ ] STREAM CONNECTED 11309
unix 3 [ ] STREAM CONNECTED 11308
unix 3 [ ] STREAM CONNECTED 11305
unix 3 [ ] STREAM CONNECTED 11304
unix 3 [ ] STREAM CONNECTED 11301
unix 3 [ ] STREAM CONNECTED 11300
unix 3 [ ] STREAM CONNECTED 11297
unix 3 [ ] STREAM CONNECTED 11296
unix 3 [ ] STREAM CONNECTED 11293
unix 3 [ ] STREAM CONNECTED 11292
unix 3 [ ] STREAM CONNECTED 11289
unix 3 [ ] STREAM CONNECTED 11288
unix 3 [ ] STREAM CONNECTED 11285
unix 3 [ ] STREAM CONNECTED 11284
unix 3 [ ] STREAM CONNECTED 11281
unix 3 [ ] STREAM CONNECTED 11280
unix 3 [ ] STREAM CONNECTED 11277
unix 3 [ ] STREAM CONNECTED 11276
unix 3 [ ] STREAM CONNECTED 11273
unix 3 [ ] STREAM CONNECTED 11272
unix 3 [ ] STREAM CONNECTED 11269
unix 3 [ ] STREAM CONNECTED 11268
unix 3 [ ] STREAM CONNECTED 11266
unix 3 [ ] STREAM CONNECTED 11265
unix 3 [ ] STREAM CONNECTED 11209
unix 3 [ ] STREAM CONNECTED 11208
unix 3 [ ] STREAM CONNECTED 11206
unix 3 [ ] STREAM CONNECTED 11205
unix 2 [ ] DGRAM 11167
unix 2 [ ] DGRAM 8661
unix 3 [ ] STREAM CONNECTED 8461
unix 3 [ ] STREAM CONNECTED 8460
unix 3 [ ] DGRAM 7139
unix 3 [ ] DGRAM 7138

ん?listenになってる??ランダムでポートが使われているってこと??

「上記コマンドで該当のPIDをを見つけ、killすれば解決する?」
[vagrant@localhost test]$ lsof -i:192.168.35.10:8000
-bash: lsof: コマンドが見つかりません

なにいいいいいいいいいい

DB hash

With a hash table, the portion of the bucket stays on disk, halving the load on memory during the search.
Arrays need to use contiguous free space in memory. When reading a large table, it is very difficult to secure a sufficient continuous area. In the case of a hash table, you can choose the key you want to use.

indexのことか?しかし、ビューハッシュとはなんだ。。。