suchen
Heimphp教程php手册Thinkphp+smarty+uploadify实现无刷新上传,thinkphpsmarty

Thinkphp+smarty+uploadify实现无刷新上传,thinkphpsmarty

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

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

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
4 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Leistungsstarke integrierte PHP-Entwicklungsumgebung

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung