php-doc-en/reference/fileinfo/functions/finfo-open.xml
Christoph Michael Becker 1543b81b4f Fix initializers
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@347865 c90b9560-bf6c-de11-be94-00142212c4b1
2019-08-17 08:49:10 +00:00

171 lines
4.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.finfo-open" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>finfo_open</refname>
<refname>finfo::__construct</refname>
<refpurpose>Create a new fileinfo resource</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>&style.procedural;</para>
<methodsynopsis role="procedural">
<type>resource</type><methodname>finfo_open</methodname>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>FILEINFO_NONE</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>magic_file</parameter><initializer>""</initializer></methodparam>
</methodsynopsis>
<para>&style.oop; (constructor):</para>
<constructorsynopsis>
<modifier>public</modifier> <methodname>finfo::__construct</methodname>
<methodparam choice="opt"><type>int</type><parameter>options</parameter><initializer>FILEINFO_NONE</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>magic_file</parameter><initializer>""</initializer></methodparam>
</constructorsynopsis>
<para>
This function opens a magic database and returns its resource.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
One or disjunction of more <link linkend="fileinfo.constants">Fileinfo
constants</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>magic_file</parameter></term>
<listitem>
<para>
Name of a magic database file, usually something like
<filename>/path/to/magic.mime</filename>. If not specified, the
<literal>MAGIC</literal> environment variable is used. If the
environment variable isn't set, then PHP's bundled magic database will
be used.
</para>
<para>
Passing &null; or an empty string will be equivalent to the default
value.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
(Procedural style only)
Returns a magic database resource on success&return.falseforfailure;.
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<warning>
<para>
The expected magic database format changed in PHP 5.3.11 and 5.4.1.
Due to this, the internal magic database was upgraded. This mostly effects
code where an external magic database is used: reading an older magic file
will now fail.
Also, some textual representations of the mime types has changed, for
instance for PHP would be "PHP script, ASCII text" instead of "PHP script
text" returned.
</para>
</warning>
<note>
<para>
Generally, using the bundled magic database (by leaving
<parameter>magic_file</parameter> and the <literal>MAGIC</literal>
environment variables unset) is the best course of action unless you
specifically need a custom magic database.
</para>
</note>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>&style.oop;</title>
<programlisting role="php">
<![CDATA[
<?php
$finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension
/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo $finfo->file($filename);
?>
]]>
</programlisting>
</example>
<example>
<title>&style.procedural;</title>
<programlisting role="php">
<![CDATA[
<?php
$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension
if (!$finfo) {
echo "Opening fileinfo database failed";
exit();
}
/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo finfo_file($finfo, $filename);
/* close connection */
finfo_close($finfo);
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
text/plain; charset=us-ascii
]]>
</screen>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>finfo_close</function></member>
</simplelist>
</para>
</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
-->