【问题标题】:Getting Uploadify Error: uploadifySettings Not A Function出现 Uploadify 错误:uploadifySettings 不是函数
【发布时间】:2013-03-23 21:45:03
【问题描述】:

我正在努力让用户通过 Uploadify 选择他们想要将文件上传到哪个文件夹。我有一堆 javascript 代码,但除了最后一点,它都可以工作。如果您愿意,我可以展示所有内容,但我坚信这不是问题。

这是我的代码:

$("#file_upload").uploadify({
        'buttonText'    : 'Upload New Files',
        'height'        : 30,
        'swf'           : 'uploadify/uploadify.swf',
        'uploader'      : 'uploadify/uploadify.php',
        'width'         : 120,
        'folder'        : $('#folder').val(),
        'auto'          : true,
        'multi'         : true,
        'onUploadComplete' : function(file) {
            location.reload();
        }
    });

    $("#folder").change(function () {
        var path = "/" + $(this).val();
        $('#file_upload').uploadifySettings("scriptData", {'folder': path });
        alert(path);
    });

此代码包含在 document.ready() 中。

这段代码的作用是

  1. 初始化uploadify函数
  2. 当用户更改#folder 的值(即下拉菜单)时,让uploadify 函数中的值“folder”发生变化。

当我单击选择框时,没有任何反应。如果我注释掉这一行:

$('#file_upload').uploadifySettings("scriptData", {'folder': path });

我收到了警报,如果我把线路留在里面,它不会做任何事情。

我咨询了 Firebug,发现我收到以下错误:

TypeError: $(...).uploadifySettings Not A Function

从逻辑上讲,我会说这意味着我没有 uploadify 没有链接到页面上。但是如果我上传文件,它就会上传,所以它就在那里并且可以工作。

这是我的 HTML/PHP:

<h3>Your Uploaded Files</h3>
    <input type="file" name="file_upload" id="file_upload">
    <span style="margin: 5px 10px 0 0; float: left;">to</span>
    <select id="folder">
        <?php
        echo '<option value="'.$directory.'">Downloads</option>';
        $friendlyDir;
        foreach(glob('downloads/*', GLOB_ONLYDIR) as $dir) {
          $friendlyDir = str_replace("downloads/","",$dir);
          echo '<option value="'.$dir.'">'.ucfirst(strtolower($friendlyDir)).'</option>';
        }
        ?>
    </select>
    <div id="file_viewer"></div>

HTML/PHP 工作正常,但我想我会包含它,这样您就可以看到触发器等是什么。

如果有人可以对此进行调查,我将不胜感激。我没有跨浏览器测试,但我使用的浏览器是 Firefox 19.0.2。

谢谢。

【问题讨论】:

    标签: javascript error-handling uploadify


    【解决方案1】:

    我最终这样做是为了在文件上使用 uploadify 功能:

    var path;
        $("#file_upload").uploadify({
            'buttonText'    : 'Upload New Files',
            'height'        : 30,
            'swf'           : 'uploadify/uploadify.swf',
            'uploader'      : 'uploadify/uploadify.php',
            'width'         : 120,
            'folder'        : $('#folder').val(),
            'auto'          : true,
            'multi'         : true,
            'folder'        : path,
            'onUploadStart' : function(file) {
               $('#file_upload').uploadify("settings", 'formData', {'folder' : path});
            },
            'onUploadSuccess' : function(file, data, response) {
                //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
                location.reload();
            }
        });
    
        $("#folder").change(function () {
            path = "/" + $(this).val();
        });
    

    在uploadify.php上我把它改成了这样:

    //$targetFolder = '/file/downloads'; // Relative to the root
    $targetFolder = "/file".$_POST['folder'];
    
    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
    
    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png','pdf','doc','docx'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    
    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo $targetFolder;
    } else {
        echo 'Invalid file type.';
    }
    }
    

    现在它可以工作了:D

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多