Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳
更新時間:2015年07月30日 09:55:02 作者:mma-php
這篇文章主要介紹了Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳的方法,實例分析了php模板與js上傳插件結合實現(xiàn)無刷新上傳的相關技巧,需要的朋友可以參考下
本文實例講述了Thinkphp+smarty+uploadify實現(xiàn)無刷新上傳的方法。分享給大家供大家參考。具體如下:
模板文件代碼:
<!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',
//發(fā)送給后臺的其他參數(shù)通過formData指定
//'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
"method" : 'post',//方法,服務端可以用$_POST數(shù)組獲取數(shù)據(jù)
'removeTimeout' : 1,
"onUploadSuccess" : uploadPicture
});
//可以根據(jù)自己的要求來做相應處理
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數(shù)據(jù) */
$this->ajaxReturn($arr);
}
}
希望本文所述對大家的php程序設計有所幫助。
您可能感興趣的文章:
- ThinkPHP文件上傳實例教程
- ThinkPHP結合AjaxFileUploader實現(xiàn)無刷新文件上傳的方法
- Thinkphp多文件上傳實現(xiàn)方法
- thinkPHP3.2簡單實現(xiàn)文件上傳的方法
- 封裝ThinkPHP的一個文件上傳方法實例
- ThinkPHP實現(xiàn)帶驗證碼的文件上傳功能實例
- Thinkphp3.2簡單解決多文件上傳只上傳一張的問題
- layui框架實現(xiàn)文件上傳及TP3.2.3(thinkPHP)對上傳文件進行后臺處理操作示例
- 使用ThinkPHP+Uploadify實現(xiàn)圖片上傳功能
- 解決ThinkPHP下使用上傳插件Uploadify瀏覽器firefox報302錯誤的方法
- 基于ThinkPHP+uploadify+upload+PHPExcel 無刷新導入數(shù)據(jù)
- Thinkphp5+uploadify實現(xiàn)的文件上傳功能示例
相關文章
在CentOS系統(tǒng)上從零開始搭建WordPress博客的全流程記錄
這篇文章主要介紹了在CentOS系統(tǒng)中從零開始搭建WordPress站點的全流程記錄,使用最大眾的Apache服務器和MySQL數(shù)據(jù)庫環(huán)境,需要的朋友可以參考下2016-04-04
關于 Laravel Redis 多個進程同時取隊列問題詳解
這篇文章主要給大家介紹了關于 Laravel Redis 多個進程同時取隊列問題的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或工作具有一定的參考學習價值,需要的朋友下面來一起學習學習吧。2017-12-12
laravel 數(shù)據(jù)遷移與 Eloquent ORM的實現(xiàn)方法
laravel 提供了很實用的 Eloquent ORM 模型類,簡單、直觀的與數(shù)據(jù)庫進行交互。同時使用數(shù)據(jù)遷移管理數(shù)據(jù)庫,可以與團隊進行共享以及編輯,本文詳細的介紹了laravel 數(shù)據(jù)遷移與 Eloquent ORM的實現(xiàn)方法,感興趣的可以了解一下2019-04-04

