Javascript 多线程文件名更改

Javascript 多线程文件名更改,javascript,Javascript,该插件应该有一个内置的唯一名称转换器,但似乎不起作用。不确定问题是什么 <div class="upload-form" id="uploader"> <!-- Form Heading --> <h1 class="replace-text">Upload Form</h1> <a href="#" class="close" title="Close Window"><img src="img/clo

该插件应该有一个内置的唯一名称转换器,但似乎不起作用。不确定问题是什么

<div class="upload-form" id="uploader">

    <!-- Form Heading -->
    <h1 class="replace-text">Upload Form</h1>
    <a href="#" class="close" title="Close Window"><img src="img/close-button.png" alt="Close"></a>

    <!-- Select & Upload Button -->
    <div>
        <a class="button" id="pickfiles" href="#">Select</a>
        <a class="button" id="uploadfiles" href="#">Upload</a>
    </div>

    <!-- File List -->
    <div id="filelist" class="cb"></div>

    <!-- Progress Bar -->
    <div id="progressbar"></div>

    <!-- Close After Upload -->
    <div id="closeAfter">
        <span class="checkbox">
            <input type="checkbox" name="checkbox" id="checkbox">
            <label for="checkbox">Close window after upload</label>
        </span>
    </div>

</div><!-- close uploader -->

上传表单
上传后关闭窗口
这是我的小文件上传程序,下面是将信息处理到S3存储桶中的脚本

<script>
// Upload Form
        $(function() {
            // Settings ////////////////////////////////////////////////
            var uploader = new plupload.Uploader({
                runtimes : 'html5,flash,silverlight', // Set runtimes, here it will use HTML5, if not supported will use flash, etc.
                unique_names: true,
                browse_button : 'pickfiles', // The id on the select files button
                multi_selection: true, // Allow to select one file each time
                container : 'uploader', // The id of the upload form container
                max_file_size : '800kb', // Maximum file size allowed
                url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
                multipart: true,
                multipart_params: {
                    'key': '<?=$slug?>/${filename}', // use filename as a key
                    'Filename': '${filename}', // adding this to keep consistency across the runtimes
                    'acl': 'public-read',
                    'Content-Type': 'image/jpeg',
                    'success_action_status': '201',
                    'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',       
                    'policy': '<?php echo $policy; ?>',
                    'signature': '<?php echo $signature; ?>'
                },
                flash_swf_url : '<?php echo get_stylesheet_directory_uri(); ?>/js/plupload.flash.swf', // The url to thye flash file
                silverlight_xap_url : '<?php echo get_stylesheet_directory_uri(); ?>/js/plupload.silverlight.xap', // The url to the silverlight file

                filters : [ {title : "Image files", extensions : "jpg,gif,png"} ] // Filter the files that will be showed on the select files window
            });

            // RUNTIME
            uploader.bind('Init', function(up, params) {
                $('#runtime').text(params.runtime);
            });

            // Start Upload ////////////////////////////////////////////
            // When the button with the id "#uploadfiles" is clicked the upload will start
            $('#uploadfiles').click(function(e) {
                uploader.start();
                e.preventDefault();
            });

            uploader.init(); // Initializes the Uploader instance and adds internal event listeners.

            // Selected Files //////////////////////////////////////////
            // When the user select a file it wiil append one div with the class "addedFile" and a unique id to the "#filelist" div.
            // This appended div will contain the file name and a remove button
            uploader.bind('FilesAdded', function(up, files) {
                $.each(files, function(i, file) {
                    $('#filelist').append('<div class="addedFile" id="' + file.id + '">' + file.name + '<a href="#" id="' + file.id + '" class="removeFile"></a>' + '</div>');
                });
                up.refresh(); // Reposition Flash/Silverlight
            });

            // Error Alert /////////////////////////////////////////////
            // If an error occurs an alert window will popup with the error code and error message.
            // Ex: when a user adds a file with now allowed extension
            uploader.bind('Error', function(up, err) {
                alert("Error: " + err.code + ", Message: " + err.message + (err.file ? ", File: " + err.file.name : "") + "");
                up.refresh(); // Reposition Flash/Silverlight
            });

            // Remove file button //////////////////////////////////////
            // On click remove the file from the queue
            $('a.removeFile').live('click', function(e) {
                uploader.removeFile(uploader.getFile(this.id));
                $('#'+this.id).remove();
                e.preventDefault();
            });

            // Progress bar ////////////////////////////////////////////
            // Add the progress bar when the upload starts
            // Append the tooltip with the current percentage
            uploader.bind('UploadProgress', function(up, file) {
                var progressBarValue = up.total.percent;
                $('#progressbar').fadeIn().progressbar({
                    value: progressBarValue
                });
                $('#progressbar .ui-progressbar-value').html('<span class="progressTooltip">' + up.total.percent + '%</span>');
            });

            // Close window after upload ///////////////////////////////
            // If checkbox is checked when the upload is complete it will close the window
            uploader.bind('UploadComplete', function() {
                if ($('.upload-form #checkbox').attr('checked')) {
                    $('.upload-form').fadeOut('slow');
                }
            });

            // Close window ////////////////////////////////////////////
            // When the close button is clicked close the window
            $('.upload-form .close').on('click', function(e) {
                $('.upload-form').fadeOut('slow');
                e.preventDefault();
            });

        }); // end of the upload form configuration

        // Check Box Styling
        $(document).ready(function() {

            var checkbox = $('.upload-form span.checkbox');

            // Check if JavaScript is enabled
            $('body').addClass('js');

            // Make the checkbox checked on load
            checkbox.addClass('checked').children('input').attr('checked', true);

            // Click function
            checkbox.on('click', function() {

                if ($(this).children('input').attr('checked')) {
                    $(this).children('input').attr('checked', false);
                    $(this).removeClass('checked');
                }

                else {
                    $(this).children('input').attr('checked', true);
                    $(this).addClass('checked');
                }

            });

        });
        </script>

//上传表单
$(函数(){
//背景////////////////////////////////////////////////
var uploader=新的plupload.uploader({
运行时:“html5,flash,silverlight”,//设置运行时,这里它将使用html5,如果不支持,将使用flash等。
唯一的名称:true,
浏览按钮:“pickfiles”,//选择文件按钮上的id
multi_selection:true,//允许每次选择一个文件
容器:“uploader”,//上载表单容器的id
最大文件大小:“800kb”,//允许的最大文件大小
网址:'http://.s3.amazonaws.com/',
多部分:正确,
多部分参数:{
'key':'/${filename}',//将filename用作键
'Filename':'${Filename}',//添加此项以保持运行时的一致性
“acl”:“公共读取”,
“内容类型”:“图像/jpeg”,
“成功行动状态”:“201”,
“AWSAccessKeyId”:“,
“政策”:“,
“签名”:”
},
flash_swf_url:'/js/plupload.flash.swf',//指向flash文件的url
silverlight_xap_url:'/js/plupload.silverlight.xap',//指向silverlight文件的url
过滤器:[{title:“图像文件”,扩展名:“jpg,gif,png”}]//过滤将显示在“选择文件”窗口中的文件
});
//运行时
uploader.bind('Init',函数(up,params){
$('#runtime').text(params.runtime);
});
//开始上传////////////////////////////////////////////
//单击id为“#uploadfiles”的按钮后,上载将开始
$(“#上载文件”)。单击(函数(e){
uploader.start();
e、 预防默认值();
});
uploader.init();//初始化uploader实例并添加内部事件侦听器。
//选定文件//////////////////////////////////////////
//当用户选择一个文件时,它会在“#filelist”div中附加一个带有类“addedFile”的div和唯一id。
//这个附加的div将包含文件名和一个remove按钮
uploader.bind('FilesAdded',函数(up,files){
$.each(文件、函数(i、文件){
$(“#文件列表”).append(“”+file.name+“”+“”);
});
up.refresh();//重新定位Flash/Silverlight
});
//错误警报/////////////////////////////////////////////
//如果发生错误,将弹出一个带有错误代码和错误消息的警报窗口。
//例如:当用户添加具有现在允许的扩展名的文件时
uploader.bind('Error',函数(up,err){
警报(“错误:“+err.code+”,消息:“+err.Message+(err.file?”,文件:“+err.file.name:”)+”;
up.refresh();//重新定位Flash/Silverlight
});
//删除文件按钮//////////////////////////////////////
//单击从队列中删除文件
$('a.removeFile').live('click',函数(e){
removeFile(uploader.getFile(this.id));
$('#'+this.id).remove();
e、 预防默认值();
});
//进度条////////////////////////////////////////////
//在上载开始时添加进度条
//使用当前百分比追加工具提示
uploader.bind('UploadProgress',函数(up,file){
var progressBarValue=up.total.percent;
$('#progressbar').fadeIn().progressbar({
值:progressBarValue
});
$('#progressbar.ui progressbar value').html('+-up.total.percent+'%');
});
//上传后关闭窗口///////////////////////////////
//如果在上传完成时选中复选框,它将关闭窗口
uploader.bind('UploadComplete',function(){
if($('.upload form#checkbox').attr('checked')){
$('.upload form').fadeOut('slow');
}
});
//关窗////////////////////////////////////////////
//单击“关闭”按钮后,关闭窗口
$('.upload form.close')。打开('click',函数(e){
$('.upload form').fadeOut('slow');
e、 预防默认值();
});
}); // 上传表单配置结束
//复选框样式
$(文档).ready(函数(){
var checkbox=$('.upload form span.checkbox');
//检查是否启用了JavaScript
$('body').addClass('js');
//在加载时选中复选框
checkbox.addClass('checked')。children('input')。attr('checked',true);
//点击功能
复选框。在('单击',函数()上){
if($(this).children('input').attr('checked')){
$(this).children('input').attr('checked',false);
$(this.removeClass('checked');
}
否则{
$(this).children('input').attr('checked',true);
$(this).addClass('
$(function() {
            var filen = uniqid('<?=$slug?>', true);
            // Settings ////////////////////////////////////////////////
            var uploader = new plupload.Uploader({

                runtimes : 'html5,flash,silverlight', // Set runtimes, here it will use HTML5, if not supported will use flash, etc.
                browse_button : 'pickfiles', // The id on the select files button
                multi_selection: true, // Allow to select one file each time
                container : 'uploader', // The id of the upload form container
                max_file_size : '800kb', // Maximum file size allowed
                url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
                multipart: true,
                multipart_params: {
                    'key': '<?=$slug?>/'+ filen +'${filename}', // use filename as a key
                    'Filename': filen+'${filename}', // adding this to keep consistency across the runtimes
                    'acl': 'public-read',
                    'Content-Type': 'image/jpeg',
                    'success_action_status': '201',
                    'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',       
                    'policy': '<?php echo $policy; ?>',
                    'signature': '<?php echo $signature; ?>'
                },
                flash_swf_url : '<?php echo get_stylesheet_directory_uri(); ?>/js/plupload.flash.swf', // The url to thye flash file
                silverlight_xap_url : '<?php echo get_stylesheet_directory_uri(); ?>/js/plupload.silverlight.xap', // The url to the silverlight file

                filters : [ {title : "Image files", extensions : "jpg,gif,png"} ] // Filter the files that will be showed on the select files window
            });