jquery自定義插件開發(fā)之window的實現(xiàn)過程
717
2024-03-06
本文實例講述了Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳的方法。分享給大家供大家參考。具體如下:
模板文件代碼:
<!DOCTYPE html> <html lang="cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" /> <script src="http://www.gimoo.net/t/1512/<{$smarty.const.PUBLIC_PATH}>/Uploadify/jquery.js" type="text/javascript"></script> <script src="http://www.gimoo.net/t/1512/<{$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>
控制器代碼:
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 ThinkUpload($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è)計有所幫助。
#免責聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進行刪除處理。敬請諒解!