Uploadify效果很好,我喜欢它。但是,我只是无法弄清楚如何制作一个下拉列表来选择要选择的上传文件夹。我希望我的用户能够选择要上传文件的文件夹。有人知道这样做的好方法吗?最好是简单的。
答案 0 :(得分:3)
这很简单。
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : $("#folder").val(),
'auto' : true
});
});
$("#folder").change(function() {
$('#file_upload').uploadifySettings('folder',$("#folder").val());
});
</script>
并使用文件夹值进行html选择。
<select id="folder">
<option value="/uploads">Uploads</option>
<option value="/videos">Videos</option>
<option value="/music">Music</option>
</select>
答案 1 :(得分:0)
轻微错误....
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : $("#folder").val(),
'auto' : true
});
}); // should not be here - goes above </script>
$("#folder").change(function() {
$('#file_upload').uploadifySettings('folder',$("#folder").val());
});
</script>
我的代码(忽略脚本的位置/我也将文件夹设置为#folder的第一个选项,这在我的下拉列表中恰好是dubstep)
js head section
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : 'upload/uploadify.swf',
'script' : 'upload/uploadify.php',
'cancelImg' : 'upload/cancel.png',
'folder' : 'upload/dropbox/dubmin',
'fileExt' : '*.mp3',
'fileDesc' : '.mp3 files only',
'multi' : true,
'queueSizeLimit' : 4,
'queueID' : 'queue',
'sizeLimit' : 52428800,
'wmode' : 'transparent'
});
$("#folder").change(function () {
var path = "upload/dropbox/" + $(this).val();
$('#file_upload').uploadifySettings('folder', path);
});
/* begin test to see if js switching to correct folder (remove or comment out section when done) */
$('#test').click(function(){
var folderz = $('#file_upload').uploadifySettings('folder');
alert("folder is set to: "+folderz);
});
/* begin test to see if js switching to correct folder */
});
</script>
html代码
<select id="folder" name="folder">
<option value="dubtem">Dubstep</option>
<option value="liqmin">Liquid</option>
<option value="drknro">Neuro</option>
<option value="other">Other</option>
</select>
<button type="button" id="test">Which Folder?</button>
</p>
<input id="file_upload" name="file_upload" type="file" />
<div id="queue"></div>
<a href="javascript:$('#file_upload').uploadifyUpload();"><img src="submit.png" id="submit_img"></a>
完成后,用html或js注释掉或删除测试部分。