首页 > 其他 > 详细

解决swfupload上传文件session失效

时间:2014-05-14 17:10:29      阅读:395      评论:0      收藏:0      [点我收藏+]

使用flash插件上传,可能是很多人选择的方式,但是随之而来的session丢失问题也着实让人头疼

swfupload代码如下:

<script type="text/javascript" src=\‘#\‘"  echo base_url();?>/static/js/swfupload/swfupload/swfupload.js"></script>
<script type="text/javascript" src=\‘#\‘"  echo base_url();?>/static/js/swfupload/js/swfupload.queue.js"></script>
<script type="text/javascript" src=\‘#\‘"  echo base_url();?>/static/js/swfupload/js/fileprogress.js"></script>
<script type="text/javascript" src=\‘#\‘"  echo base_url();?>/static/js/swfupload/js/handlers.js"></script>
<script type="text/javascript">
var swfu;
var settings = {} ;
window.onload = function() {
 settings = {
flash_url : "<?php echo base_url() ;?>/static/js/swfupload/swfupload/swfupload.swf",
upload_url: "<?php echo site_url(‘admin/file_manager/file/upload_file‘) ;?>?inajax=1",
post_params: {"session":"<?php echo session_id() ;?>"},
file_size_limit : "1000 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: true,
// Button settings
//button_image_url: "/js/swfupload/images/TestImageNoText_65x29.png",
button_image_url:‘<?php echo base_url() ;?>/static/js/swfupload/images/bg.png‘,
button_width: "63",
button_height: "20",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: ‘<a class="theFont">批量上传</a>‘,
button_text_style: ".theFont{ font-size: 12; color:black ; cursor:pointer;text-align:center}",
button_text_left_padding: 0,
button_text_top_padding: 0,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : success_data,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete// Queue plugin event
};
swfu = new SWFUpload(settings);
     };
               
 function uploadComplete(){
//alert(3);
 }
 function uploadStart(){
 swfu.addPostParam("SubPath",path);
               
 }
 function success_data(file, serverData) {
alert(serverData);
}
</script>

上面的我在post后面加了个参数session=<?php echo sessionid(); ?>

在php端

if(!empty($_POST[‘session‘]) && isset($_POST[‘session‘])){
@session_id($_POST[‘session‘]);
}
@ob_clean() ;
@session_start();

另外还有个问题,他的传递参数是window.onload 但是我要得到某个文本框的值,那就没办法了,所以我在后面加了一个函数

function uploadStart(){}在post提交之前在后面追加参数即可

解决swfupload上传文件session失效,布布扣,bubuko.com

解决swfupload上传文件session失效

原文:http://taoyouth.blog.51cto.com/2793776/1410868

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!