看tp的源碼,I函數看到這麼一句:
case 'get' :
$input =& $_GET;
break;
case 'post' :
$input =& $_POST;
break;
case 'put' :
if(is_null($_PUT)){
parse_str(file_get_contents('php://input'), $_PUT);
}
$input = $_PUT;
break;
這個input是個什麼鬼?
自己做了小實驗:
首先一個表單,有三種方式get post 和一個enctype="multipart/form-data文件上傳屬性,代碼簡單:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<!-- <form action="./input.php" method="POST" enctype="multipart/form-data"> -->
<!-- <form action="./input.php" method="POST" > -->
<form action="./input.php" method="GET" >
<input type="text" name='name' />
<input type="password" name='password' />
<input type="submit" />
</form>
</body>
</html>
然後一個input.php接收:
<?php
/*
php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype=”multipart/form-data”
比HTTP_RAW_POST_DATA佔用更小內存,不需要在ini中設置
*/
var_dump($_POST);
echo '<hr>';
$raw_post_data = file_get_contents('php://input', 'r');
var_dump($raw_post_data);
echo '<hr>';
// 需要設置 always_populate_raw_post_data 爲on ,在php.ini 中,前面的分號去掉即可
var_dump($GLOBALS['HTTP_RAW_POST_DATA']);
/*
結論:
1.php://input 無法讀取到 表單類型爲 enctype=multipart/form-data的數據
2.而$GLOBALS['HTTP_RAW_POST_DATA']在PHP在無法識別的 Content-Type的情況下,將POST過來的數據原樣地填入變量$http_raw_post_data,但是也無法讀取到Content- Type爲multipart/form-data的POST數據。
3.GET的數據他們三個(POST,INPUT ,HTTP_RAW_POST_DATA都拿不到)
*/
結論寫在註釋裏了,配上四幅圖:
第一個圖:
method爲input,並且phpini中開啓了
always_populate_raw_post_data 爲on
可以看到三者完全一樣。
第二幅圖,看看他的請求頭:
第三張圖,是表單中加入了enctype="multipart/form-data"屬性,
再看一下上面加入enctype="multipart/form-data"的請求頭: