Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery文件上载仅用于用户界面?_Php_Javascript_Jquery_Html_Jquery File Upload - Fatal编程技术网

Php jQuery文件上载仅用于用户界面?

Php jQuery文件上载仅用于用户界面?,php,javascript,jquery,html,jquery-file-upload,Php,Javascript,Jquery,Html,Jquery File Upload,我想上传多个文件。用例是:我网站上的用户可以上传多张照片 现在我只是在使用 <input type="file" name="myfiles" multiple="multiple"> 所以这个blueimp jquery文件上传脚本有漂亮的UI,正是我要找的。然而,有几个问题: 1) 我想提交一个php文件的形式,这将决定是否上传文件与否 2) 我的表单有许多其他字段。我想通过普通的旧post提交按钮和我表格的其余部分一起提交。这可能吗 如果没有,有人能推荐一个更好的选择吗 谢谢

我想上传多个文件。用例是:我网站上的用户可以上传多张照片

现在我只是在使用

<input type="file" name="myfiles" multiple="multiple">
所以这个blueimp jquery文件上传脚本有漂亮的UI,正是我要找的。然而,有几个问题:

1) 我想提交一个php文件的形式,这将决定是否上传文件与否

2) 我的表单有许多其他字段。我想通过普通的旧post提交按钮和我表格的其余部分一起提交。这可能吗

如果没有,有人能推荐一个更好的选择吗


谢谢

通过blueimp文件上传插件,上述所有功能都可以实现

1) 决定是否上传文件

使用插件中的
add:
选项对添加了文件名的服务器进行单独的ajax调用,并使用响应筛选要上载的文件列表

https://github.com/blueimp/jQuery-File-Upload
2) 将表单中的其他数据添加到上载

使用插件中的
formData:
选项添加表单中的其他字段,以便在提交时传递给服务器

因此,类似于以下内容:

$('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        autoUpload: false,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 5000000, // 5 MB
        loadImageMaxFileSize: 15000000, // 15MB
        formData: $("#myForm").serializeArray()
    }).on('fileuploadadd', function (e, data) {
        data.context = $('<div/>').appendTo('#files');

        $.ajax(
               url: "/checkfiles",
               data: { files: data.files },
               success: function(result) {
                  // assume server passes back list of accepted files
                  $.each(result.files, function (index, file) {
                    var node = $('<p/>')
                       .append($('<span/>').text(file.name));
                    if (!index) {
                      node
                        .append('<br>')
                        .append(uploadButton.clone(true).data(data));
                    }
                    node.appendTo(data.context);
                  });
               }
    }).on('fileuploadprocessalways', function (e, data) {
        var index = data.index,
            file = data.files[index],
            node = $(data.context.children()[index]);
        if (file.preview) {
            node
                .prepend('<br>')
                .prepend(file.preview);
        }
        if (file.error) {
            node
                .append('<br>')
                .append(file.error);
        }
        if (index + 1 === data.files.length) {
            data.context.find('button')
                .text('Upload')
                .prop('disabled', !!data.files.error);
        }
    }).on('fileuploaddone', function (e, data) {
        $.each(data.result.files, function (index, file) {
            var link = $('<a>')
                .attr('target', '_blank')
                .prop('href', file.url);
            $(data.context.children()[index])
                .wrap(link);
        });
    }).on('fileuploadfail', function (e, data) {
        $.each(data.result.files, function (index, file) {
            var error = $('<span/>').text(file.error);
            $(data.context.children()[index])
                .append('<br>')
                .append(error);
        });
    });
});
$('#fileupload')。fileupload({
url:url,
数据类型:“json”,
自动上载:false,
acceptFileTypes:/(\.\/)(gif | jpe?g | png)$/i,
最大文件大小:5000000,//5 MB
loadImageMaxFileSize:15000000,//15MB
formData:$(“#myForm”).serializeArray()
}).on('fileuploadadd',函数(e,数据){
data.context=$('').appendTo('#文件');
$.ajax(
url:“/checkfiles”,
数据:{files:data.files},
成功:功能(结果){
//假设服务器传回已接受文件的列表
$.each(result.files,函数(索引,文件){
变量节点=$(“

”) .append($('').text(file.name)); 如果(!索引){ 节点 .append(“
”) .append(uploadButton.clone(true).data(data)); } appendTo(data.context); }); } }).on('fileuploadprocessalways',函数(e,数据){ var指数=data.index, file=data.files[index], node=$(data.context.children()[index]); if(file.preview){ 节点 .prepend(“
”) .prepend(file.preview); } if(file.error){ 节点 .append(“
”) .append(file.error); } if(索引+1==data.files.length){ data.context.find('按钮') .text(“上载”) .prop('disabled',!!data.files.error); } }).on('fileuploaddone',函数(e,数据){ $.each(data.result.files,函数(索引,文件){ 变量链接=$('') .attr('target','u blank') .prop('href',file.url); $(data.context.children()[index]) .wrap(link); }); }).on('fileuploadfail',函数(e,数据){ $.each(data.result.files,函数(索引,文件){ var error=$('').text(file.error); $(data.context.children()[index]) .append(“
”) .append(错误); }); }); });


但如果我需要显示预览容器和响应后服务器,请在此容器中设置图像?