0514-86177077
9:00-17:00(工作日)
視圖層
!!!自己下載jquery文件和ajaxfileUpload的插件
!DOCTYPE html> html> head lang="en"> meta charset="UTF-8"> title>/title> style> /style> /head> script type="text/javascript"> //下面用于圖片上傳預覽功能 function setImagePreview(avalue) { var docObj=document.getElementById("doc"); var imgObjPreview=document.getElementById("preview"); if(docObj.files docObj.files[0]) { //火狐下,直接設img屬性 imgObjPreview.style.display = 'block'; //imgObjPreview.src = docObj.files[0].getAsDataURL(); //火狐7以上版本不能用上面的getAsDataURL()方式獲取,需要一下方式 imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]); } else { //IE下,使用濾鏡 docObj.select(); var imgSrc = document.selection.createRange().text; var localImagId = document.getElementById("localImag"); //必須設置初始大小 localImagId.style.width = "150px"; localImagId.style.height = "180px"; //圖片異常的捕捉,防止用戶修改后綴來偽造圖片 try{ localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"; localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc; } catch(e) { alert("您上傳的圖片格式不正確,請重新選擇!"); return false; } imgObjPreview.style.display = 'none'; document.selection.empty(); } ajaxFileUpload(); //上傳圖片 return true; } /script> body> center> label> @foreach ($arr as $key=>$val) {{-- img src="{{$val->n_img}}" alt="" height="100" width="100" class="qq"> input type="file" id="file1" style="VISIBILITY: hidden" >--}} img id="preview" width="100" height="100" src="{{$val->n_img}}"> input type="file" name="touxiang" id="doc" style="display:none" οnchange="javascript:setImagePreview();"> @endforeach /label> /center> /body> /html> script src="./js.js">/script> script src="./ajaxfileupload.js">/script> script type="text/javascript"> function ajaxFileUpload() { $.ajaxFileUpload ( { url: "{{url('up_img')}}", //用于文件上傳的服務器端請求地址 secureuri: false, //是否需要安全協(xié)議,一般設置為false fileElementId: 'doc' } ); return false; } /script>
控制器層
?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use DB; use Illuminate\Support\Facades\Input; class ImgController extends Controller { public function Index(){ $arr= DB::select("SELECT * FROM r_nav limit 1"); return view('index',['arr'=>$arr]); } //修改圖片 public function up_img(Request $Request){ $n_file = Input::file('touxiang'); if($n_file->isValid()){ //獲取文件名稱 $clientName = $n_file -> getClientOriginalName(); $realPath = $n_file -> getRealPath(); //獲取圖片格式 $entension = $n_file -> getClientOriginalExtension(); //圖片保存路徑 $mimeTye = $n_file -> getMimeType(); $path = $n_file -> move('IMG'); } $ress = DB::table('r_nav')->where('n_id',11)->update(['n_img'=>$path]); } }
以上這篇在laravel5.2中實現(xiàn)點擊用戶頭像更改頭像的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
標簽:佳木斯 通化 香港 自貢 寶雞 郴州 金華 阿克蘇
上一篇:Yii框架數(shù)據(jù)庫查詢、增加、刪除操作示例
下一篇:laravel 5.3 單用戶登錄簡單實現(xiàn)方法
Copyright ? 1999-2012 誠信 合法 規(guī)范的巨人網(wǎng)絡通訊始建于2005年
蘇ICP備15040257號-8