W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 2.0.0)
PharData::addFile — 將文件系統(tǒng)中的文件添加到 tar/zip 存檔中
public PharData::addFile(string $filename, ?string $localName = null): void
使用此方法,可以將任何文件或 URL 添加到 tar/zip 存檔中。如果 指定了可選的第二個(gè)參數(shù), 該文件將以該名稱存儲(chǔ)在存檔中,否則該參數(shù)將用作存儲(chǔ)在 存檔。URL 必須具有 localname,否則會(huì)引發(fā)異常。 此方法類似于 ZipArchive::addFile()。localnamefile
filename
要添加的磁盤上文件的完整路徑或相對路徑 到Phar檔案館。
localName
文件將存儲(chǔ)在存檔中的路徑。
無返回值,失敗時(shí)引發(fā)異常。
版本 | 說明 |
---|---|
8.0.0 | localName 現(xiàn)在是可為 null 的。 |
示例 #1 A PharData::addFile() example
<?php
try {
$a = new PharData('/path/to/my.tar');
$a->addFile('/full/path/to/file');
// demonstrates how this file is stored
$b = $a['full/path/to/file']->getContent();
$a->addFile('/full/path/to/file', 'my/file.txt');
$c = $a['my/file.txt']->getContent();
// demonstrate URL usage
$a->addFile('http://www.example.com', 'example.html');
} catch (Exception $e) {
// handle errors here
}
?>
注意: PharData::addFile(), PharData:: addFromString() 和 PharData::offsetSet() 每次調(diào)用它們時(shí)都會(huì)保存一個(gè)新的 phar 存檔。如果性能是一個(gè)問題,則應(yīng)改用 PharData::buildFromDirectory() 或 PharData::buildFromIterator()。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: