mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-30 15:58:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@325547 c90b9560-bf6c-de11-be94-00142212c4b1
158 lines
4.5 KiB
XML
158 lines
4.5 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>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>&style.oop; (constructor):</para>
|
|
<constructorsynopsis>
|
|
<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>&null;</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 this variable
|
|
is not set either, <filename>/usr/share/misc/magic</filename> is used by default.
|
|
A <literal>.mime</literal> and/or <literal>.mgc</literal> suffix is added if
|
|
needed.
|
|
</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>
|
|
As of PHP >= 5.3.11 and >= 5.4.1 the magic datababase format has changed. Due to this, the internal mime database was upgraded. This affects especially the code where external magic is read in. Reading in magic files of the older formats will not work.
|
|
|
|
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>
|
|
</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
|
|
-->
|