一直只是做企業網站,很少用到手機端管理的,所以一直沒看過手機端上傳怎么做……前段時間做了一個社區的公眾號平臺,需要用戶上傳某些內容,包括拍照、錄像等,當看到這個功能的時候就蒙了——因為沒做過,不知道怎么做……
先百度一下吧,萬能的渡娘告訴我,web手機端調用手機攝像頭實現拍照上傳原來這么簡單!
<label>照相機</label>
<input type="file" id='image' accept="image/*" capture='camera'>
<br>
<label>攝像機</label>
<input type="file" id='video' accept="video/*" capture='camcorder'>
需要注意的是老版安卓要加capture,ios加了卻要出錯。所以用js判斷iOS去掉capture:
function getIos(){
var us=navigator.userAgent.toLowerCase();
if(us.match(/iPhone\sOS/i)=='iphone os')
return true
else
return false
}
© 致遠 2020-01-18,原創內容,轉載請注明出錯:web手機端調用手機攝像頭實現拍照上傳