<html>
<from id="upfrom;">
<div style="margin-top: 10px;display:none;"> <div class="col-lg-2"> <div style="float: left; font-size: 15px;">文章封面<span style="color: red;">*</span> <span style="font-size: 7px; color: #999; margin-left: 10px;">必填</span></div> </div> <div class="col-lg-6"> <input type="file" id="picture" name="picture" class="col-lg-10 col-sm-5" style="height:30px;" placeholder="请选择文章封面" /> </div> </div>
</from>
</html>
<script>
var formData = new FormData($("#upfrom")[0]); formData.append('id', res); $.ajax({ url: '{{route('pic')}}' , type: 'POST', data: formData, async: false, cache: false, contentType: false, processData: false, success: function (returndata) { if(returndata ==1){ if(confirm('发布成功!是否继续发布?')){ window.location.href = window.location.href; }else{ window.location.href = window.history.go(-1); } } }, error: function (returndata) { return 0; } });
</script>
<?php
public function pic(Request $request){ if($request->file('picture')){ if($request->hasFile('picture')&&$request->file('picture')->isValid()){ $path='photos/upload/'; $clientName=$request->file('picture')->getClientOriginalExtension(); $clientName = time().md5('picture').'.'.$clientName; $request->file('picture')->move($path,$clientName); $imgurl = $path.$clientName; $arr['article_id']=$request->input('id'); $arr['url'] = $imgurl; $arr['status'] = '1'; $pic = $this->photo->addorupdate($this->photo->getTable(),$arr); if($pic){ return 1; }else{ return 0; } }else{ return 0; } } }
?>