一、前端上傳按鈕:
<input id="pic" name="pic" type="file">
二作谭、控制器接收?qǐng)D片放到指定目錄并把路徑存放至數(shù)據(jù)庫(kù)
if ($_FILES['pic']['tmp_name'])
{
? ? $file = request()->file('pic');
? ? if($file){
? ? ? ? $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
? ? ? ? if($info){
? ? ? ? ? ? // 成功上傳后 獲取上傳信息雏婶,位置在public/uploads/
? ? ? ? ? ? $data['pic'] = '/uploads/'.$info->getSaveName();
? ? ? ? }else{
? ? ? ? ? ? // 上傳失敗獲取錯(cuò)誤信息
? ? ? ? ? ? echo $file->getError();
? ? ? ? }
}
}
三搅窿、圖片顯示部位
<td align="center">
? ? {if condition="$vo['pic'] neq '' "}
<img src="{$vo.pic}" height="50">
? ? {else /}
暫無(wú)縮略圖
? ? {/if}
</td>