首页 > 代码库 > 解决swfupload上传文件session失效

解决swfupload上传文件session失效

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

swfupload代码如下:

<script type="text/javascript" src=http://www.mamicode.com/‘#/‘"  echo base_url();?>/static/js/swfupload/swfupload/swfupload.js"></script>
<script type="text/javascript" src=http://www.mamicode.com/‘#/‘"  echo base_url();?>/static/js/swfupload/js/swfupload.queue.js"></script>
<script type="text/javascript" src=http://www.mamicode.com/‘#/‘"  echo base_url();?>/static/js/swfupload/js/fileprogress.js"></script>
<script type="text/javascript" src=http://www.mamicode.com/‘#/‘"  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提交之前在后面追加参数即可