실제로 원하는 것은 멀티 파트 메시지가 해당 메시지와 관련하여 작동하는 방식입니다. $_POST
어레이.
는 다음과 같은 HTML 양식을 고려
<form action="/somefile.php" method="post" enctype="multipart/form-data">
<input name="text1" type="text" />
<input name="text2" type="text" />
<input name="text3" type="text" />
<input name="file" type="file" />
<input type="submit" />
</form>
지금, 우리는 file.txt
라는 파일을 선택 우리가 value1
, value2
및 value3
와 세 개의 텍스트 입력을 채울 말할 수하고 Enter 키를 제출합니다. 이것은 다음과 같이 보입니다 요구가 발생합니다 :
POST /somefile.php HTTP/1.1
Host: somehost.com
Accept: */*
User-Agent: MyBrowser/1.0
Content-Type: multipart/form-data; boundary="this-is-a-boundary-string"
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text1"
value1
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text2"
value2
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text3"
value3
--this-is-a-boundary-string
Content-Dispostion: form-data; name="file"; filename="file.txt"
Content-Type: text/plain
This is the contents of file.txt
--this-is-a-boundary-string--
우리가 print_r($_POST);
우리가 같은 것을 받아야하는 경우 우리가 PHP에서 보면 :
Array
(
[text1] => value1
[text2] => value2
[text3] => value3
)
을 ... 그리고 우리의 경우 print_r($_FILES);
: 당신이 볼 수 있도록
Array
(
[file] => Array
(
[name] => file.txt
[type] => text/plain
[size] => 32
[tmp_name] => /tmp/dskhfwe43232.tmp
[error] => 0
)
)
는 ...의 Content-Disposition:
헤더가 filename=""
요소를 포함하지 않는 메시지의 부분은에 추가 $_POST
배열이고 하나는 파일 업로드로 처리되고 $_FILES
에 추가됩니다.
multipart/form-data
메시지를 서버에 보내면 요청을 모방 한 HTML 양식을 작성하고 해당 HTML 양식의 동작에 따라 HTTP 메시지를 구성하는 것이 가장 쉬운 방법입니다.