PharData::addFromString

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 2.0.0)

PharData::addFromString — 파일 시스템의 파일을 tar/zip 아카이브에 추가합니다.


설명

public PharData::addFromString(string $localName, string $contents): void

이 메서드를 사용하면 모든 문자열을 tar/zip 아카이브에 추가할 수 있습니다. 파일은 경로로 localname을 사용하여 아카이브에 저장됩니다. 이 메서드는 ZipArchive::addFromString()과 유사합니다.


매개변수

localName
파일이 아카이브에 저장될 경로입니다.
contents
저장할 파일 내용

반환 값

반환 값이 없으며 실패 시 예외가 발생합니다.


Examples

예제 #1 PharData::addFromString() 예제

                  
<?php
try {
    $a = new PharData('/path/to/my.tar');

    $a->addFromString('path/to/file.txt', 'my simple file');
    $b = $a['path/to/file.txt']->getContent();

    // to add contents from a stream handle for large files, use offsetSet()
    $c = fopen('/path/to/hugefile.bin');
    $a['largefile.bin'] = $c;
    fclose($c);
} catch (Exception $e) {
    // handle errors here
}
?>
                  
                

노트

참고: PharData::addFile(), PharData::addFromString()PharData::offsetSet()는 호출될 때마다 새 phar 아카이브를 저장합니다. 성능이 문제인 경우 PharData::buildFromDirectory() 또는 PharData::buildFromIterator()를 대신 사용해야 합니다.


기타