使用jQuery上传多个图像

时间:2014-01-30 07:58:16

标签: php jquery image file-upload

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

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

你怎么看?你还有其他建议吗?请记住,我一次可以上传100张图片,或者一次上传2000张图片。

1 个答案:

答案 0 :(得分:0)

使用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>
相关问题