php輸入資料流php input的流量分析

來源:互聯網
上載者:User
在做一個網路攝影機拍照然後上傳的功能,php中使用php://input來擷取內容。於是就瞭解了下php://input。

從官網資訊來看,php://input是一個唯讀資訊流,當請求方式是post的,並且enctype不等於“multipart/form-data”時,可以使用php://input來擷取原始請求的資料。

看一個簡單的例子。

用戶端就是一個表單,非常簡單。

<form action="" method="POST">    name: <input type="text" name="name" value="tom" /><br />    age:<input type="text" name="age" value="22" /><br />    <input type="submit" value="Submit" /></form>

將表單提交到服務端,服務端使用file_get_contents擷取php://input內容

$content = file_get_contents("php://input");echo $content; // 輸出name=tom&amp;age=22

官網關於php://input的說明中,反覆有提到 $HTTP_RAW_POST_DATA 這個變數,這個變數其實和 file_get_contents(php://input) 的內容是一樣的。如果要開啟這個變數,需要修改設定檔,找到always_populate_raw_post_data這個選項,設定為On,然後重新啟動web伺服器,就可以了。而使用php://input不需要修改php設定檔。

在項目應用中,如網路攝影機拍照,上傳儲存,就可以用到php://input。用戶端拍照後,把圖片流傳送到服務端,服務端使用 file_get_getcontents('php://input')就能擷取到圖片流,然後把圖片流儲存到一個檔案,這個檔案就是圖片了。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.