1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00
Files
archived-doc-en/reference/zip/ziparchive/addfromstring.xml
Jim Winstead 0545e305cf Normalize version strings in changelog entries (#3672)
Now they're always N.X.Y for a PHP version, or PECL extension N.X.Y for PECL extensions.
2024-09-23 11:15:26 -07:00

149 lines
3.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ziparchive.addfromstring" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>ZipArchive::addFromString</refname>
<refpurpose>Add a file to a ZIP archive using its contents</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="ZipArchive">
<modifier>public</modifier> <type>bool</type><methodname>ZipArchive::addFromString</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>string</type><parameter>content</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>ZipArchive::FL_OVERWRITE</initializer></methodparam>
</methodsynopsis>
<para>
Add a file to a ZIP archive using its contents.
</para>
&zip.filename.separator;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<para>
The name of the entry to create.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>content</parameter></term>
<listitem>
<para>
The contents to use to create the entry. It is used in a binary
safe mode.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Bitmask consisting of
<constant>ZipArchive::FL_OVERWRITE</constant>,
<constant>ZipArchive::FL_ENC_GUESS</constant>,
<constant>ZipArchive::FL_ENC_UTF_8</constant>,
<constant>ZipArchive::FL_ENC_CP437</constant>.
The behaviour of these constants is described on the
<link linkend="zip.constants">ZIP constants</link> page.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0, PECL zip 1.18.0</entry>
<entry>
<parameter>flags</parameter> was added.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Add an entry to a new archive</title>
<programlisting role="php">
<![CDATA[
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
]]>
</programlisting>
</example>
<example>
<title>Add file to a directory inside an archive</title>
<programlisting role="php">
<![CDATA[
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->addFromString('dir/test.txt', 'file content goes here');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->