Thinkphp 3.2.2 整合Swfupload上传插件
做程序开发的人,基本上都知道SWFUpload是个文件上传利器,SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大。THINKPHP又是现在国内最流行的框架,两者的强
强联合是必然的,下面脚本100 就给大家实例讲解Thinkphp 3.2.2 整合Swfupload上传插件。
1、先从网上下载一个SWFUpload插件;
2、将SWFUpload插件复制到Public公用文件夹内;
3、将SWFUpload插件引入所需要的页面;
HTML代码:
<script type="text/javascript" src="__PUBLIC__/Swfupload/js/jquery.js"></script>
<script type="text/javascript" src="__PUBLIC__/Swfupload/js/swfupload.js"></script>
<script type="text/javascript" src="__PUBLIC__/Swfupload/js/handlers.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
upload_url: "__URL__/uploadImg", //处理上传文件方法
post_params: {"PHPSESSID": "<?php echo session_id();?>"},
file_size_limit : "40 MB",
file_types : "*.jpg;*.png;*.gif;*.bmp,*.psd;",
file_types_description : "JPG Images",
file_upload_limit : "100",
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
button_image_url : "__PUBLIC__/Swfupload/images/upload.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: 113,
button_height: 33,
button_text : '',
button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
button_text_top_padding: 0,
button_text_left_padding: 0,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,
flash_url : "__PUBLIC__/Swfupload/swf/swfupload.swf",
custom_settings : {
upload_target : "divFileProgressContainer"
},
debug: false
});
};
</script>
<div class="pro_upSucess" id="divFileProgressContainer"></div>
<div class="pro_upImg">
<ul id="pic_list">
<li>
<li>
<div class="pro_upAdd" id="spanButtonPlaceholder"></div>
</li>
</ul>
</div>
上传文件处理方法
//swfupload上传插件
public function uploadImg() {
import('ORG.Net.UploadFile');
$upload = new \ORG\Net\UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$savepath='./Uploads/image/'.date('Ymd').'/';
if (!file_exists($savepath)){
mkdir($savepath);
}
$upload->savePath = $savepath;// 设置附件上传目录
if(!$upload->upload()) {// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}else{// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
}
$str=WEB_PATH.'/'.$info[0]['savepath'].'/'.$info[0]['savename'];
print_r(str_replace("./", "", $str));
}