2013-10-12 4 views
4

У меня есть кнопка 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 раза rscripts. Это не разрушает мою СЕССИЯ. Итак, я решил использовать один скрипт для всех кнопок 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) 
        } 
    }); 
}); 

Но оба из них не работает. Кнопка не отображается.

Есть ли способ решить эту проблему?

Thank you: D. Очень ценю вашу помощь

+0

Почему вы отправляете PHPSESSID в качестве данных? если сеанс не переносится, просто используйте полный URL-адрес для загрузчика, а не относительный, или убедитесь, что у вас есть session_start() в файле uploadify.php. Не работает ли это? –

+0

Сессия должна быть перенесена. Да, есть session-start(), но это не решает проблему. –

+0

просто убедитесь, что у вас есть тот же URL-адрес, который использовался до и после входа в систему, то есть http://www.domain.com не будет переносить сеанс на http: // domain.com. Кроме того, я понимаю необходимость идентификатора сеанса в файле uploadify.php, но это не очень хорошо. Это проблема безопасности, так как каждый может перезаписать сеанс таким образом, поэтому вы должны убедиться, что session_start присутствует в файле uploadify.php и что он отлично работает с текущим сеансом. –

ответ

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(); 
} 
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.

Смежные вопросы