本文实例讲述了Thinkphp+smarty+uploadify实现无刷新上传的方法。分享给大家供大家参考。具体如下:

模板文件代码:

<!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="/UploadFiles/2021-04-02/jquery.js">

控制器代码:

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 \Think\Upload($config);// 实例化上传类
  $info = $upload->upload();
   if($info){
    $arr['errorcode'] = "0";
   } else {
    $arr["errorcode"] = "1";
    $arr["errormsg"] = $upload->getError();
   }
   /* 返回JSON数据 */
   $this->ajaxReturn($arr);
  }
}

希望本文所述对大家的php程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com