PHP開(kāi)發(fā)之前端上傳表單
首先將表單代碼貼出來(lái):
<html> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">文件名:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="上傳" /> </form> </body> </html>
這其實(shí)是一個(gè)簡(jiǎn)單form表單,但是值得注意的是enctype="multipart/form-data",enctype 屬性規(guī)定了在提交表單時(shí)要使用哪種內(nèi)容類(lèi)型,enctype="multipart/form-data"是上傳二進(jìn)制數(shù)據(jù); form里面的input的值以2進(jìn)制的方式傳過(guò)去。這個(gè)是上傳功能表單里面最重要的屬性,要注意。
再一個(gè)要注意的是action="upload.php" ,method="post"。既然是上傳就會(huì)有上傳到的地方和以什么方式上傳。action="upload.php"這個(gè)屬性是將表單內(nèi)容發(fā)向何處。
method="post"是以何種方式傳遞數(shù)據(jù)。
表單頁(yè)面還是很簡(jiǎn)單的,不過(guò)也要自己親自動(dòng)手嘗試一下,這樣才會(huì)記憶深刻。