无法使用onuploadstart和formdata将值传递给uploadify

时间:2015-09-16 11:20:29

标签: php jquery uploadify

当我添加 formData 部分'formData' : {'gallery_choice' : 'EMPTY'}时,代码仍然有效,但我希望使用{{{}将'EMPTY'更改为所选的库1}}或其他任何工作(但我需要的值保存为全局)。

当我添加 onUploadStart 部分(在下面的代码部分中添加)时, uploadify.swf 文件停止工作,我会看到后退选项(一个无聊的HTML“选择文件”按钮而不是花哨的闪光按钮 - 我做错了什么?

<?php $GLOBALS['gallery_choice'] ?>

如果有人想要它,这里也是 uploadify.php 文件:

<script type="text/javascript">
$(function() {
    $('#file_upload').uploadify({
        //'auto'     : false,
        'formData' : {'gallery_choice' : 'EMPTY'},
        'swf'      : 'uploadify.swf',
        'uploader' : 'uploadify.php',
        'queueSizeLimit' : 10,
        'width'    : 150,
        'height'   : 20,
        'buttonText' : 'V&aelig;lg Filer',
        'checkExisting' : '/check-exists.php',
        'fileTypeDesc' : 'Image Files',
        'fileTypeExts' : '*.gif; *.jpg; *.png',
        'fileSizeLimit' : '400KB',
        //'uploadLimit' : 20
        // Put your options here
        'overrideEvents' : ['onSelectError','onDialogClose','onUploadStart'],
        'onUploadStart' : function(file){
                    $('#file_upload').uploadify('settings','gallery_choice','TEMP'});
                    },
        'onSelectError' : function(file, errorCode, errorMsg) {
          switch(errorCode) {    
          case 110:
            alert('ALERT! File is to big! The File: "' + file.name + '" is larger than the maximum size of 400KB! The file was not uploaded!');       
          break;
          case 130:
            alert('ALERT! INCORRECT FILE TYPE! The file: "' + file.name + '" is not of the allowed type (.jpg, .png eller .gif)! The file was not uploaded!');
          break;
          case 120:
            alert('ALERT! THE FILE IS EMPTY! The file: "' + file.name + '" is empty (0 bytes)! The file was not uploaded!');
          break;          
          default:
            alert('ALERT! The file: "' + file.name + '" made an error with the error code: ' + errorCode + ', as well as the following message: ' + errorMsg + '  The file was not uploaded!!');     
          }
        }
    });
});
</script>

我用谷歌搜索和Stack-Overflowed,但找不到解决方案。

1 个答案:

答案 0 :(得分:0)

我在Flash按钮未亮起时遇到的问题是由于此行'formData' : {'gallery_choice' : 'EMPTY'},

当我将其更改为'formData' : {'gallery_choice' : '<?php echo $GLOBALS['gallery_choice']; ?>'},时 它开始工作了,一旦我想在我的 Uploadify.php 中使用 $ _ POST 而不是 $ _ GET ,它就开始工作 - 这就是更新到Uploadify.php:

if(isset($_POST['gallery_choice'])){
    $targetFolder = 'uploads/' . $_POST['gallery_choice'] . '/';
}else
    $targetFolder = 'uploads/TEMP/';