4

我的页面中有 4 个上传按钮。这是我的代码:

$(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 个上传按钮使用一个脚本。我试过这样做:

$('.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。非常感谢您的帮助

4

2 回答 2

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 键的单引号。

于 2013-10-22T13:26:21.013 回答
2

你是从官方文档中得到的吗?我即将:

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();
}
于 2013-10-18T11:55:34.367 回答