php讀取zip內(nèi)容的方法-創(chuàng)新互聯(lián)

這篇文章主要介紹php讀取zip內(nèi)容的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),托里網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:托里等地區(qū)。托里做網(wǎng)站價(jià)格咨詢:13518219792

zip_entry_read()函數(shù)是PHP中內(nèi)置的函數(shù),用于從打開的zip歸檔條目中讀取內(nèi)容。正在讀取zip條目,返回的字節(jié)數(shù)可以作為參數(shù)發(fā)送給zip_entry_read()函數(shù),如果成功,它將返回指定zip條目的內(nèi)容,否則將返回PHP警告。

語法:

string zip_entry_read( $zip_entry, $length )

參數(shù):

該函數(shù)接受兩個(gè)參數(shù),如下所述。

$zip_entry:這是一個(gè)指定zip條目資源的強(qiáng)制參數(shù)。

$length:它是一個(gè)可選參數(shù),指定要返回的字節(jié)數(shù)。

返回值:

成功時(shí)返回指定zip條目的內(nèi)容,否則返回PHP警告。

錯(cuò)誤和異常:

如果zip存檔無效,zip_entry_read()函數(shù)將返回ER_OPEN錯(cuò)誤。

如果zip存檔為空,則zip_entry_read()函數(shù)返回ER_NOZIP錯(cuò)誤

下面的程序演示了PHP中的zip_entry_read()函數(shù):

示例1:

假設(shè)zip文件article.zip包含文件:geeks.txt

<?php 
  
// 打開zip文件
$zip_handle = zip_open("C:/xampp/htdocs/articles.zip"); 
   
// 讀取zip存檔項(xiàng)
while($zip_entry = zip_read($zip_handle))  
{  
    $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); 
    $file_name = zip_entry_name($zip_entry); 
    
    if ($resource == true)  
    {  
   
        // 讀取zip存檔項(xiàng)的內(nèi)容
        $file_content = zip_entry_read($zip_entry); 
        echo("File: " . $file_name . " successfully opened. <br>"); 
        echo("File content: " . $file_content); 
   
        // 關(guān)閉zip歸檔項(xiàng)
        zip_entry_close($zip_entry); 
    }  
    else
        echo("Failed to Open."); 
} 
  
// 關(guān)閉zip文件
zip_close($zip_handle); 
?>

輸出:

File: articles/geeks successfully opened. 
File content: Welcome to GeeksforGeeks. It is a computer science portal
where you can learn programming.

示例2:

假設(shè)zip文件article.zip包含以下文件:

geeks.txt

geeks1.txt

<?php 
  
$zip_handle = zip_open("C:/xampp/htdocs/articles.zip"); 
   
while($zip_entry = zip_read($zip_handle))  
{  
    $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); 
    $file_name = zip_entry_name($zip_entry); 
    if ($resource == true)  
    {  
   
        // 讀取zip存檔項(xiàng)的內(nèi)容,最多可達(dá)150字節(jié)
        $file_content = zip_entry_read($zip_entry, 150); 
        echo("File Name: " . $file_name . " is opened Successfully. <br>"); 
        echo($file_content); 
        echo("<br><br>"); 
  
       
        zip_entry_close($zip_entry); 
    }  
    else
        echo("Failed to Open."); 
}  
  
zip_close($zip_handle); 
?>

輸出:

File Name: articles/geeks is opened Successfully. 
Welcome to GeeksforGeeks. It is a computer science portal where you
can learn programming.

File Name: articles/geeks1 is opened Successfully. 
A Computer Science portal for geeks. It contains well written, well
thought and well-explained computer science and programming articles,
quizzes and many more.

以上是php讀取zip內(nèi)容的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文標(biāo)題:php讀取zip內(nèi)容的方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://muchs.cn/article4/dhgdoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站收錄、搜索引擎優(yōu)化微信公眾號(hào)、面包屑導(dǎo)航、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司