2013-03-23 124 views
0

我正在为用户选择要将文件上传到Uploadify的文件夹的方式。我有一堆javascript代码,但它除了最后一点之外都可以工作。如果你愿意,我可以展示一切,但我坚信这不是问题。获取Uploadify错误:uploadifySettings不是函数

这里是我的代码:

$("#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. 已经在uploadify函数值“文件夹”,当用户改变#folder的值(这是下拉改变)。

当我点击选择框时,什么也没有发生。如果我注释掉行:

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

我得到的警报,车针,如果我离开了线它没有做任何事情。

我咨询过萤火虫,看到我正在以下错误:

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。

谢谢。

回答

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