PHP编程:Thinkphp+smarty+uploadify实现无刷新上传
发布时间:2020-12-13 02:47:56 所属栏目:PHP教程 来源:网络整理
导读:《Thinkphp+smarty+uploadify实现无刷新上传》要点: 本文介绍了Thinkphp+smarty+uploadify实现无刷新上传,希望对您有用。如果有疑问,可以联系我们。 本篇章节讲解Thinkphp+smarty+uploadify实现无刷新上传的办法.供大家参考研究.具体如下: PHP应
《Thinkphp+smarty+uploadify实现无刷新上传》要点: 本篇章节讲解Thinkphp+smarty+uploadify实现无刷新上传的办法.分享给大家供大家参考.具体如下:PHP应用 模板文件代码: <!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',//发送给后台的其他参数通过formData指定 //'formData': { 'someKey': 'someValue','someOtherKey': 1 },"method" : 'post',//办法,服务端可以用$_POST数组获取数据 'removeTimeout' : 1,"onUploadSuccess" : uploadPicture }); //可以根据自己的要求来做相应处理 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)) { //图片上传设置 $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数据 */ $this->ajaxReturn($arr); } } 希望本文所述对大家的php程序设计有所赞助. 编程之家培训学院每天发布《Thinkphp+smarty+uploadify实现无刷新上传》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |