Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน zip_read() ใน PHP

ฟังก์ชัน zip_read() ใช้สำหรับอ่านรายการถัดไปในไฟล์บีบีบอัด ZIP

รูปแบบการใช้งาน (Syntax)

zip_read(zip)

พารามิเตอร์ (Parameters)

  • zip − ทรัพยากร ZIP ที่ต้องการอ่าน

ค่าที่ส่งกลับ (Return Value)

ฟังก์ชัน zip_read() ส่งคืนทรัพยากรที่บรรจุไฟล์ภายในอาร์คีฟ ZIP เมื่อสำเร็จ

ตัวอย่างการใช้งาน

ตัวอย่าง สมมติว่าเรามีไฟล์ ZIP ชื่อ "new.zip" ซึ่งมีไฟล์ดังนี้:

amit.txt peter.txt result.html demo.java settings.ini

โค้ดตัวอย่าง:

<?php 
$zip = zip_open("new.zip"); 
if ($zip) { 
    while ($zip_entry = zip_read($zip)) { 
        echo "File Name = " . zip_entry_filename($zip_entry) . "<br/>"; 
    } 
    zip_close($zip); 
} 
?>

ผลลัพธ์ (Output)

File Name = amit.txt File Name = peter.txt File Name = result.html File Name = demo.java File Name = settings.ini