<?php
$link = mysqli_connect('localhost','******','********','testdb');
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
$sql = "select * from tb_member limit 0,5";
$result=mysqli_query($conn,$sql);
while($data=mysqli_fetch_array($result)){
echo "$data[mem_id] $data[title] $data[name] $data[surname]<br>";
}
?>ผลลัพธ์A001001 นาย เอเอ สกุลเอ
A001002 นาง บีบี สกุลบี
A001003 นางสาว ซีซี สกุลซี
A001004 นางสาว ดีดี สกุลดี
<?php
if(isset($_GET['z1'])){
header('Content-Type: image/jpeg');
$result = file_get_contents("zip://files/test.zip#img1.jpg");
echo $result;
exit;
}
if(isset($_GET['z2'])){
header('Content-type: image/jpeg');
$zipfile = dirname(__FILE__) .'/files/test.zip';
$zip = new ZipArchive;
$zip->open($zipfile);
$im_string = $zip->getFromName('img1.jpg');
$im = imagecreatefromstring($im_string);
$zip->close();
imagejpeg($im);
imagedestroy($im);
exit;
}
if(isset($_GET['z3'])){
header('Content-type: image/jpeg');
$zipfile = dirname(__FILE__) .'/files/test-password.zip';
$zip = new ZipArchive;
$zip->open($zipfile);
$zip->setPassword("123456");
$im_string = $zip->getFromName('img1.jpg');
$im = imagecreatefromstring($im_string);
$zip->close();
imagejpeg($im);
imagedestroy($im);
exit;
}
if(isset($_GET['z4'])){
$rootPath = realpath('/files/testdir');
$zipfile = dirname(__FILE__) .'/files/test.zip';
$zip = new ZipArchive;
if ($zip->open($zipfile, ZipArchive::OVERWRITE) === TRUE) {
$path = dirname(__FILE__) .'/files/testdir/test.jpg';
if(file_exists($path)){
$zip->addFile($path, '/test.jpg') or die('error');
$zip->close();
echo 'ok';
}else{
echo 'no file';
}
} else {
echo 'failed';
}
exit;
}
if(isset($_GET['z5'])){
$zipfile = dirname(__FILE__) .'/files/test.zip';
$zip = zip_open($zipfile);
$dirs = $files = array();
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$zen = zip_entry_name($zip_entry);
$is_dir = substr($zen, -1) == DIRECTORY_SEPARATOR;
$zen_splitted = explode(DIRECTORY_SEPARATOR, $zen);
if ($is_dir) {
$dirs[] = $zen_splitted[count($zen_splitted)-2];
} else {
$files[] = $zen_splitted[count($zen_splitted)-1];
}
}
zip_close($zip);
}
print_r($dirs);
print_r($files);
exit;
}
?>
<img src="/code/php/zip.php?z1">
ผลลัพธ์
<img src="/code/php/zip.php?z2">
ผลลัพธ์
<img src="/code/php/zip.php?z3">ผลลัพธ์