欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Thinkphp+smarty+uploadify實(shí)現(xiàn)無(wú)刷新上傳

 更新時(shí)間:2015年07月30日 09:55:02   作者:mma-php  
這篇文章主要介紹了Thinkphp+smarty+uploadify實(shí)現(xiàn)無(wú)刷新上傳的方法,實(shí)例分析了php模板與js上傳插件結(jié)合實(shí)現(xiàn)無(wú)刷新上傳的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Thinkphp+smarty+uploadify實(shí)現(xiàn)無(wú)刷新上傳的方法。分享給大家供大家參考。具體如下:

模板文件代碼:

<!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',
    //后臺(tái)處理的頁(yè)面
    'uploader': "<{U('home/Login/Uploads','',false)}>",
    //按鈕顯示的文字
    'buttonText': '上傳圖片',
     //顯示的高度和寬度
    "height" : 30,
    'fileTypeDesc': 'Image Files',
    //允許上傳的文件后綴
    'fileTypeExts': '*.gif; *.jpg; *.png',
    //發(fā)送給后臺(tái)的其他參數(shù)通過(guò)formData指定
    //'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
    "method" : 'post',//方法,服務(wù)端可以用$_POST數(shù)組獲取數(shù)據(jù)
    'removeTimeout'  : 1,
    "onUploadSuccess" : uploadPicture
  });
  //可以根據(jù)自己的要求來(lái)做相應(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 \Think\Upload($config);// 實(shí)例化上傳類(lèi)
  $info = $upload->upload();
   if($info){
    $arr['errorcode'] = "0";
   } else {
    $arr["errorcode"] = "1";
    $arr["errormsg"] = $upload->getError();
   }
   /* 返回JSON數(shù)據(jù) */
   $this->ajaxReturn($arr);
  }
}

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論