我的页面中有4个uploadify按钮。这是我的代码:
$(function() {
$('#file_upload').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload1').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify1.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload2').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify2.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload3').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify3.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
});
问题是它正在摧毁我的SESSION数据。当我删除3个其他的脚本。它并没有破坏我的会话。所以,我决定在页面中的所有4 uploadify按钮上使用一个脚本。我试过这样做:
$('.file_upload').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
即便如此:
$(".file_upload").each(function() {
$(this).uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
});
但他们两个都行不通。该按钮不会出现。
有什么办法可以解决吗?
谢谢你:D。非常感谢您的帮助
答案 0 :(得分:2)
你是否从official doc开始。我是关于:
formData : { '<?php echo session_name();?>' : '<?php echo session_id();?>' }
并在uploadify.php
$session_name = session_name(); if (!isset($_POST[$session_name])) { exit; } else { session_id($_POST[$session_name]); session_start(); }
答案 1 :(得分:2)
$('.selectorClass').uploadify({
formData:{
PHPSESSID: '<?=session_id()?>',
timestamp: '<?php echo $timestamp;?>',
token : '<?php echo md5('unique_salt' . $timestamp);?>'
},
swf : 'uploadify.swf',
uploader : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
onQueueComplete: function() {
setTimeout(function(){location.reload(true);},100)
}
});
在查看uplodify的源代码之后,我发现传递给uplodify的对象没有像这样的单引号的键
var settings = $.extend({
// Required Settings
id : $this.attr('id'), // The ID of the DOM object
swf : 'uploadify.swf', // The path to the uploadify SWF file
uploader : 'uploadify.php', // The path to the server-side upload script
// Options
auto : true, // Automatically upload files when added to the queue
buttonClass : '', // A class name to add to the browse button DOM object
buttonCursor : 'hand', // The cursor to use with the browse button
buttonImage : null, // (String or null) The path to an image to use for the Flash browse button if not using CSS to style the button
buttonText : 'SELECT FILES', // The text to use for the browse button
checkExisting : false, // The path to a server-side script that checks for existing files on the server
debug : false, // Turn on swfUpload debugging mode
fileObjName : 'Filedata', // The name of the file object to use in your server-side script
fileSizeLimit : 0, // The maximum size of an uploadable file in KB (Accepts units B KB MB GB if string, 0 for no limit)
fileTypeDesc : 'All Files', // The description for file types in the browse dialog
fileTypeExts : '*.*', // Allowed extensions in the browse dialog (server-side validation should also be used)
height : 30, // The height of the browse button
method : 'post', // The method to use when sending files to the server-side upload script
multi : true, // Allow multiple file selection in the browse dialog
formData : {}, // An object with additional data to send to the server-side upload script with every file upload
preventCaching : true, // Adds a random value to the Flash URL to prevent caching of it (conflicts with existing parameters)
progressData : 'percentage', // ('percentage' or 'speed') Data to show in the queue item during a file upload
queueID : false, // The ID of the DOM object to use as a file queue (without the #)
queueSizeLimit : 999, // The maximum number of files that can be in the queue at one time
removeCompleted : true, // Remove queue items from the queue when they are done uploading
removeTimeout : 3, // The delay in seconds before removing a queue item if removeCompleted is set to true
requeueErrors : false, // Keep errored files in the queue and keep trying to upload them
successTimeout : 30, // The number of seconds to wait for Flash to detect the server's response after the file has finished uploading
uploadLimit : 0, // The maximum number of files you can upload
width : 120, // The width of the browse button
// Events
overrideEvents : [] // (Array) A list of default event handlers to skip
/*
onCancel // Triggered when a file is cancelled from the queue
onClearQueue // Triggered during the 'clear queue' method
onDestroy // Triggered when the uploadify object is destroyed
onDialogClose // Triggered when the browse dialog is closed
onDialogOpen // Triggered when the browse dialog is opened
onDisable // Triggered when the browse button gets disabled
onEnable // Triggered when the browse button gets enabled
onFallback // Triggered is Flash is not detected
onInit // Triggered when Uploadify is initialized
onQueueComplete // Triggered when all files in the queue have been uploaded
onSelectError // Triggered when an error occurs while selecting a file (file size, queue size limit, etc.)
onSelect // Triggered for each file that is selected
onSWFReady // Triggered when the SWF button is loaded
onUploadComplete // Triggered when a file upload completes (success or error)
onUploadError // Triggered when a file upload returns an error
onUploadSuccess // Triggered when a file is uploaded successfully
onUploadProgress // Triggered every time a file progress is updated
onUploadStart // Triggered immediately before a file upload starts
*/
}, options);
这可能是你的问题背后的原因,试试这个,删除侧面json键的单引号。