|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- $Revision$ --> |
| 3 | +<!-- EN-Revision: 4bf789e981af0836c41daa16e57ef86c21497faa Maintainer: ippey Status: ready --> |
| 4 | +<!-- Credits: ippey --> |
| 5 | +<refentry xml:id="function.request-parse-body" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 6 | + <refnamediv> |
| 7 | + <refname>request_parse_body</refname> |
| 8 | + <refpurpose>リクエストボディを読み取り、解析して結果を返す</refpurpose> |
| 9 | + </refnamediv> |
| 10 | + |
| 11 | + <refsect1 role="description"> |
| 12 | + &reftitle.description; |
| 13 | + <methodsynopsis> |
| 14 | + <type>array</type><methodname>request_parse_body</methodname> |
| 15 | + <methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>options</parameter><initializer>&null;</initializer></methodparam> |
| 16 | + </methodsynopsis> |
| 17 | + <simpara> |
| 18 | + この関数は リクエストボディを読み取り、 |
| 19 | + <literal>Content-Type</literal> ヘッダーに基づき解析します。 |
| 20 | + 現在、2つのコンテンツタイプをサポートしています: |
| 21 | + </simpara> |
| 22 | + <itemizedlist> |
| 23 | + <listitem> |
| 24 | + <simpara> |
| 25 | + <literal>application/x-www-form-urlencoded</literal> |
| 26 | + </simpara> |
| 27 | + </listitem> |
| 28 | + <listitem> |
| 29 | + <simpara> |
| 30 | + <literal>multipart/form-data</literal> |
| 31 | + </simpara> |
| 32 | + </listitem> |
| 33 | + </itemizedlist> |
| 34 | + <simpara> |
| 35 | + この関数は、 <literal>POST</literal> 以外のHTTPメソッドで送信された |
| 36 | + <literal>multipart/form-data</literal> を解析するために使用されます。 |
| 37 | + これらのリクエストでは、スーパーグローバルの |
| 38 | + <varname>$_POST</varname> や <varname>$_FILES</varname> は自動的に設定されません。 |
| 39 | + </simpara> |
| 40 | + <caution> |
| 41 | + <simpara> |
| 42 | + <function>request_parse_body</function> は、リクエストボディを |
| 43 | + <literal>php://input</literal> ストリームにバッファせずに処理します。 |
| 44 | + </simpara> |
| 45 | + </caution> |
| 46 | + </refsect1> |
| 47 | + |
| 48 | + <refsect1 role="parameters"> |
| 49 | + &reftitle.parameters; |
| 50 | + <variablelist> |
| 51 | + <varlistentry> |
| 52 | + <term><parameter>options</parameter></term> |
| 53 | + <listitem> |
| 54 | + <simpara> |
| 55 | + <parameter>options</parameter> パラメータは連想配列を受け取り、 |
| 56 | + リクエストボディの解析に関連する以下のグローバル &php.ini; の設定を上書きします。 |
| 57 | + </simpara> |
| 58 | + <itemizedlist> |
| 59 | + <listitem><simpara><literal>max_file_uploads</literal></simpara></listitem> |
| 60 | + <listitem><simpara><literal>max_input_vars</literal></simpara></listitem> |
| 61 | + <listitem><simpara><literal>max_multipart_body_parts</literal></simpara></listitem> |
| 62 | + <listitem><simpara><literal>post_max_size</literal></simpara></listitem> |
| 63 | + <listitem><simpara><literal>upload_max_filesize</literal></simpara></listitem> |
| 64 | + </itemizedlist> |
| 65 | + </listitem> |
| 66 | + </varlistentry> |
| 67 | + </variablelist> |
| 68 | + </refsect1> |
| 69 | + |
| 70 | + <refsect1 role="returnvalues"> |
| 71 | + &reftitle.returnvalues; |
| 72 | + <simpara> |
| 73 | + <function>request_parse_body</function> は、 <varname>$_POST</varname> に相当するものを |
| 74 | + インデックス <literal>0</literal> に、 <varname>$_FILES</varname> に相当するものを <literal>1</literal> に |
| 75 | + 持つ配列ペアを返します。 |
| 76 | + </simpara> |
| 77 | + </refsect1> |
| 78 | + |
| 79 | + <refsect1 role="errors"> |
| 80 | + &reftitle.errors; |
| 81 | + <simpara> |
| 82 | + <literal>Content-Type</literal> ヘッダーに基づいて解析を試み、リクエストボディが無効な場合、 |
| 83 | + <exceptionname>RequestParseBodyException</exceptionname> をスローします。 |
| 84 | + </simpara> |
| 85 | + <simpara> |
| 86 | + <parameter>options</parameter> に無効なキーが含まれている、 |
| 87 | + または、対応するキーに無効な値が設定されている場合は、 |
| 88 | + <exceptionname>ValueError</exceptionname> をスローします。 |
| 89 | + </simpara> |
| 90 | + </refsect1> |
| 91 | + |
| 92 | + <refsect1 role="examples"> |
| 93 | + &reftitle.examples; |
| 94 | + <example xml:id="function.request-parse-body.example.basic"> |
| 95 | + <title><function>request_parse_body</function> の例</title> |
| 96 | + <programlisting role="php"> |
| 97 | +<![CDATA[ |
| 98 | +<?php |
| 99 | +// Parse request and store result in the $_POST and $_FILES superglobals. |
| 100 | +[$_POST, $_FILES] = request_parse_body(); |
| 101 | +// Echo the content of some transferred file |
| 102 | +echo file_get_contents($_FILES['file_name']['tmp_name']); |
| 103 | +?> |
| 104 | +]]> |
| 105 | + </programlisting> |
| 106 | + </example> |
| 107 | + <example xml:id="function.request-parse-body.example.options"> |
| 108 | + <title>オプションを設定した <function>request_parse_body</function> の例</title> |
| 109 | + <programlisting role="php"> |
| 110 | +<![CDATA[ |
| 111 | +<?php |
| 112 | +// form.php |
| 113 | +
|
| 114 | +assert_logged_in(); |
| 115 | +
|
| 116 | +// Only for this form, we allow a bigger upload size. |
| 117 | +[$_POST, $_FILES] = request_parse_body([ |
| 118 | + 'post_max_size' => '10M', |
| 119 | + 'upload_max_filesize' => '10M', |
| 120 | +]); |
| 121 | +
|
| 122 | +// Do something with the uploaded files. |
| 123 | +?> |
| 124 | +]]> |
| 125 | + </programlisting> |
| 126 | + </example> |
| 127 | + </refsect1> |
| 128 | +</refentry> |
| 129 | +<!-- Keep this comment at the end of the file |
| 130 | +Local variables: |
| 131 | +mode: sgml |
| 132 | +sgml-omittag:t |
| 133 | +sgml-shorttag:t |
| 134 | +sgml-minimize-attributes:nil |
| 135 | +sgml-always-quote-attributes:t |
| 136 | +sgml-indent-step:1 |
| 137 | +sgml-indent-data:t |
| 138 | +indent-tabs-mode:nil |
| 139 | +sgml-parent-document:nil |
| 140 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 141 | +sgml-exposed-tags:nil |
| 142 | +sgml-local-catalogs:nil |
| 143 | +sgml-local-ecat-files:nil |
| 144 | +End: |
| 145 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 146 | +vim: et tw=78 syn=sgml |
| 147 | +vi: ts=1 sw=1 |
| 148 | +--> |
0 commit comments