【问题标题】:Multiple images uploader using jQuery使用 jQuery 上传多张图片
【发布时间】:2014-01-30 07:58:15
【问题描述】:

我想创建一个可以上传多张图片的 PHP 代码。我只有一件事在努力。我得到了上传图片的代码,但问题是浏览器超时。例如,如果我想同时上传 250 张图像,它将开始处理它,直到超时,因此不会上传所有图像。

我想了一会儿,我想如果我可以使用jQuery Ajax,我可以将图像发送到幕后并上传到那里,也许我不会收到超时错误。我是这么想的,因为一次上传一张图片应该不会导致超时错误,所以如果我可以把所有的图片都拍下来,并通过jQuery将它们一张一张发送上传,它可能会起作用。

你怎么看?你还有什么建议吗?请记住,我一次可以上传 100 张图片,甚至一次可以上传 2000 张图片。

【问题讨论】:

    标签: php jquery image file-upload


    【解决方案1】:

    使用pluploader插件,它是一个很棒的插件,非常适合上传多个文件,您可以在服务器端脚本轻松处理:

    这是一个示例代码:

    <!---------HTML ------------->
    
     <div id="uploader">
            <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
        </div>
    
      <!-------------JS -----------------> 
        <script type="text/javascript">
        // Initialize the widget when the DOM is ready
        $(function() {
            $("#uploader").plupload({
                // General settings
                runtimes : 'html5,flash,silverlight,html4',
                url : "examples/upload",
    
                // Maximum file size
                max_file_size : '2mb',
    
                chunk_size: '1mb',
    
                // Resize images on clientside if we can
                resize : {
                    width : 200,
                    height : 200,
                    quality : 90,
                    crop: true // crop to exact dimensions
                },
    
                // Specify what files to browse for
                filters : [
                    {title : "Image files", extensions : "jpg,gif,png"},
                    {title : "Zip files", extensions : "zip,avi"}
                ],
    
                // Rename files by clicking on their titles
                rename: true,
    
                // Sort files
                sortable: true,
    
                // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
                dragdrop: true,
    
                // Views to activate
                views: {
                    list: true,
                    thumbs: true, // Show thumbs
                    active: 'thumbs'
                },
    
                // Flash settings
                flash_swf_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/flash/Moxie.cdn.swf',
    
                // Silverlight settings
                silverlight_xap_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/silverlight/Moxie.cdn.xap'
            });
        });
        </script>
    

    【讨论】:

    • 谢谢!他们有 jQuery 的文档吗?我所看到的只是使用原始 JavaScript 的文档。在您的示例中,您使用了 jQuery,那么是否有 jQuery 文档?
    • 是的,但这并不是真正的文档,而是一个示例。我想知道如何实现它并查看所有可能的选项。
    • 谢谢!我是否必须编写用于上传的服务器端脚本?如果我这样做了,我猜它会在发送文件上传之前验证文件吗?
    • 没错,使用 $_FILES['filename'] 其中 filename 是您要发送的文件的名称!
    猜你喜欢
    • 1970-01-01
    • 2011-07-06
    • 2015-05-05
    • 2015-07-22
    • 2022-01-16
    • 2017-04-08
    相关资源
    最近更新 更多