《PHP編程:Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳》要點:
本文介紹了PHP編程:Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳,希望對您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:thinkphp教程
本文實例講述了Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳的辦法.分享給大家供大家參考.具體如下:PHP應(yīng)用
模板文件代碼:PHP應(yīng)用
<!DOCTYPE html> <html lang="cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="<{$smarty.const.PUBLIC_PATH}>/Uploadify/uploadify.css" rel="stylesheet" type="text/css" /> <script src="<{$smarty.const.PUBLIC_PATH}>/Uploadify/jquery.js" type="text/javascript"></script> <script src="<{$smarty.const.PUBLIC_PATH}>/Uploadify/jquery.uploadify.min.js" type="text/javascript"></script> </head> <script type="text/javascript"> $(function() { $("#file_upload").uploadify({ //指定swf文件 'swf': '<{$smarty.const.PUBLIC_PATH}>/Uploadify/uploadify.swf', //后臺處理的頁面 'uploader': "<{U('home/Login/Uploads','',false)}>", //按鈕顯示的文字 'buttonText': '上傳圖片', //顯示的高度和寬度 "height" : 30, 'fileTypeDesc': 'Image Files', //允許上傳的文件后綴 'fileTypeExts': '*.gif; *.jpg; *.png', //發(fā)送給后臺的其他參數(shù)通過formData指定 //'formData': { 'someKey': 'someValue', 'someOtherKey': 1 }, "method" : 'post',//辦法,服務(wù)端可以用$_POST數(shù)組獲取數(shù)據(jù) 'removeTimeout' : 1, "onUploadSuccess" : uploadPicture }); //可以根據(jù)自己的要求來做相應(yīng)處理 function uploadPicture(file, data){ var data = eval('(' + data + ')'); if(data.errorcode){ alert(data.errormsg); } else { alert(data.errormsg); } } }); </script> <body> <input type="file" name="file_upload" id="file_upload" /> </body> </html>
控制器代碼:PHP應(yīng)用
public function uploads(){ $arr = array( "errorcode"=>"1","errormsg"=>"上傳成功!"); $model = M('applicant'); if (!empty($_FILES)) { //圖片上傳設(shè)置 $config = array( 'maxSize' => 1000000, 'rootPath' => 'Public', 'savePath' => '/Uploads/', 'saveName' => array('uniqid',''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => false, 'subName' => array('date','Ymd'), ); $upload = new \Think\Upload($config);// 實例化上傳類 $info = $upload->upload(); if($info){ $arr['errorcode'] = "0"; } else { $arr["errorcode"] = "1"; $arr["errormsg"] = $upload->getError(); } /* 返回JSON數(shù)據(jù) */ $this->ajaxReturn($arr); } }
希望本文所述對大家的php程序設(shè)計有所贊助.PHP應(yīng)用
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP編程:Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳》等實戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/8979.html