このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
slim:4:cookbook [2020/10/13 17:26] y2sunlight [Retrieving Current Route] |
slim:4:cookbook [2020/10/13 21:59] (現在) y2sunlight [Uploading files using POST forms] |
||
---|---|---|---|
行 24: | 行 24: | ||
===== ルートパターンの末尾のスラッシュ(/ | ===== ルートパターンの末尾のスラッシュ(/ | ||
- | Slim treats a URL pattern with a trailing slash as different to one without. That is, ''/ | + | Slimは、末尾にスラッシュがあるURLパターンを、無いものとは異なるものとして扱います。つまり、''/ |
- | + | ||
- | Slimは、末尾にスラッシュがあるURLパターンを、ないものとは異なるものとして扱います。 つまり、''/ | + | |
For GET requests a permanent redirect is fine, but for other request methods like POST or PUT the browser will send the second request with the GET method. To avoid this you simply need to remove the trailing slash and pass the manipulated url to the next middleware. | For GET requests a permanent redirect is fine, but for other request methods like POST or PUT the browser will send the second request with the GET method. To avoid this you simply need to remove the trailing slash and pass the manipulated url to the next middleware. | ||
- | GETリクエストの場合、永続的なリダイレクトは問題ありませんが、POSTやPUTなどの他のリクエストメソッドの場合、ブラウザはGETメソッドを使用して2番目のリクエストを送信します。 これを回避するには、末尾のスラッシュを削除し、操作されたURLを次のミドルウェアに渡す必要があります。 | + | GETリクエストの場合、パーマネント(permanent)リダイレクトは問題ありませんが、POSTやPUTなどの他のリクエストメソッドの場合、ブラウザはGETメソッドを使用して2番目のリクエストを送信します。これを回避するには、単に、末尾のスラッシュを削除し、操作されたURLを次のミドルウェアに渡す必要があります。 |
- | + | ||
- | If you want to redirect/ | + | |
- | ''/'' | + | ''/'' |
<code php> | <code php> | ||
行 73: | 行 69: | ||
</ | </ | ||
- | Alternatively, | + | あるいは、[[https:// |
- | + | ||
- | または、[[https:// | + | |
<code php> | <code php> | ||
行 138: | 行 132: | ||
\\ | \\ | ||
- | ===== Setting up CORS ===== | + | ===== CORSの設定 |
- | CORS - Cross origin resource sharing | + | CORS - クロス オリジンリソース シェアリング(オリジン間リソース共有) |
- | A good flowchart for implementing | + | * CORSサポートを実装するための適切なフローチャートリファレンス: \\ [[https:// |
+ | * CORSサポートはここでテストできます:[[http:// | ||
+ | * ここで仕様を読むことができます:[[https:// | ||
- | CORS server flowchart | + | > 参考:https:// |
+ | ==== シンプル ソリューション ==== | ||
- | You can test your CORS Support here: http:// | + | 単純なCORSリクエストの場合、サーバーはレスポンスに次のヘッダーを追加するだけで済みます。 |
- | You can read the specification here: https:// | + | < |
- | + | ||
- | CORS-クロスオリジンリソースシェアリング | + | |
- | + | ||
- | CORSサポートを実装するための適切なフローチャートリファレンス: | + | |
- | + | ||
- | CORSサーバーのフローチャート | + | |
- | + | ||
- | CORSサポートはここでテストできます:http:// | + | |
- | + | ||
- | ここで仕様を読むことができます:https:// | + | |
- | ==== The simple solution ==== | + | |
- | + | ||
- | For simple CORS requests, the server only needs to add the following header to its response: | + | |
- | + | ||
- | 単純なCORSリクエストの場合、サーバーは応答に次のヘッダーを追加するだけで済みます。 | + | |
- | + | ||
- | < | + | |
Access-Control-Allow-Origin: | Access-Control-Allow-Origin: | ||
</ | </ | ||
行 171: | 行 151: | ||
The following code should enable lazy CORS. | The following code should enable lazy CORS. | ||
- | 次のコードは、レイジーCORSを有効にする必要があります。 | + | 次のコードは、Lazy CORS を有効にする必要があります。 |
<code php> | <code php> | ||
行 186: | 行 166: | ||
}); | }); | ||
</ | </ | ||
- | |||
- | Add the following route as the last route: | ||
最後のルートとして次のルートを追加します: | 最後のルートとして次のルートを追加します: | ||
行 207: | 行 185: | ||
==== Access-Control-Allow-Methods ==== | ==== Access-Control-Allow-Methods ==== | ||
- | |||
- | The following middleware can be used to query Slim’s router and get a list of methods a particular pattern implements. | ||
- | |||
- | Here is a complete example application: | ||
次のミドルウェアを使用して、Slimのルーターにクエリを実行し、特定のパターンが実装するメソッドのリストを取得できます。 | 次のミドルウェアを使用して、Slimのルーターにクエリを実行し、特定のパターンが実装するメソッドのリストを取得できます。 | ||
行 327: | 行 301: | ||
==== Access-Control-Allow-Credentials ==== | ==== Access-Control-Allow-Credentials ==== | ||
- | If the request contains credentials (cookies, authorization headers or TLS client certificates), | + | リクエストに資格情報(Cookie、承認ヘッダー、またはTLSクライアント証明書)が含まれている場合は、レスポンスオブジェクトに '' |
- | + | ||
- | 要求に資格情報(Cookie、承認ヘッダー、またはTLSクライアント証明書)が含まれている場合は、応答オブジェクトに '' | + | |
<code php> | <code php> | ||
行 337: | 行 309: | ||
\\ | \\ | ||
- | ===== Uploading files using POST forms ===== | + | ===== POSTフォームを使ったファイルのアップロード |
- | + | ||
- | Files that are uploaded using forms in POST requests can be retrieved with the Request method getUploadedFiles(). | + | |
POSTリクエストのフォームを使用してアップロードされたファイルは、Requestメソッド '' | POSTリクエストのフォームを使用してアップロードされたファイルは、Requestメソッド '' | ||
- | |||
- | When uploading files using a POST request, make sure your file upload form has the attribute '' | ||
POSTリクエストを使用してファイルをアップロードする場合は、ファイルアップロードフォームに属性 '' | POSTリクエストを使用してファイルをアップロードする場合は、ファイルアップロードフォームに属性 '' | ||
- | If multiple files are uploaded for the same input name, add brackets after the input name in the HTML, otherwise only one uploaded file will be returned for the input name by getUploadedFiles(). | + | 同じ |
- | + | ||
- | 同じ入力名に対して複数のファイルがアップロードされる場合は、HTMLの入力名の後に括弧を追加します。そうでない場合、'' | + | |
- | + | ||
- | Below is an example HTML form that contains both single and multiple file uploads. | + | |
以下は、単一ファイルと複数ファイルの両方のアップロードを含むHTMLフォームの例です。 | 以下は、単一ファイルと複数ファイルの両方のアップロードを含むHTMLフォームの例です。 | ||
行 382: | 行 346: | ||
</ | </ | ||
</ | </ | ||
- | |||
- | Uploaded files can be moved to a directory using the moveTo method. Below is an example application that handles the uploaded files of the HTML form above. | ||
アップロードされたファイルは、'' | アップロードされたファイルは、'' |