Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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 在通过javascript或jquery从客户端上传文件之前,如何检测上传文件的数量及其名称?_Php_Javascript_Jquery_File Upload_Client Side - Fatal编程技术网

Php 在通过javascript或jquery从客户端上传文件之前,如何检测上传文件的数量及其名称?

Php 在通过javascript或jquery从客户端上传文件之前,如何检测上传文件的数量及其名称?,php,javascript,jquery,file-upload,client-side,Php,Javascript,Jquery,File Upload,Client Side,我想上传多个文件,并有一个名为test.php的文件,其中包含以下代码: <!doctype html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.8.0.min.js"></script> <script> $(function(){ var myVar; $('form').submit(function(){ myV

我想上传多个文件,并有一个名为test.php的文件,其中包含以下代码:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">

<script src="js/jquery-1.8.0.min.js"></script>
<script>
$(function(){
var myVar;
$('form').submit(function(){
    myVar = setInterval(ajax, 1000);
});
var ajax = function() {
    $.ajax({
        url: 'test2.php',
        type: 'post',
        success: function(ajax_result){
            $('.result').html(ajax_result);
            if (!ajax_result) {
                clearInterval(myVar);
            }
        },
        error: function(){
            alert('error');
        }
    });
};
});
</script>
</head>
<body style="width:100%; height:100%;">
<form action="test2.php" target="iframe" method="post" enctype="multipart/form-data" >
    <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="fil" />
    <input name="file[]" type="file" multiple />
    <input type="submit">
</form>
<iframe id="iframe" name="iframe"></iframe>
<div class="result" style="width:100%; height:100%;"></div>

</body>
</html>
<?php
session_start();
if (isset($_FILES['file'])){
for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
move_uploaded_file($_FILES['file']['tmp_name'][$i],'a/'.$_FILES['file']['name'][$i]);
}
}
if (isset($_SESSION[$key = ini_get("session.upload_progress.prefix") . 'fil'])) {
     var_dump($_SESSION[$key]);

} else echo false;
?>

$(函数(){
var-myVar;
$('form')。提交(函数(){
myVar=setInterval(ajax,1000);
});
var ajax=function(){
$.ajax({
url:'test2.php',
键入:“post”,
成功:函数(ajax\u结果){
$('.result').html(ajax_result);
如果(!ajax_result){
净距(myVar);
}
},
错误:函数(){
警报(“错误”);
}
});
};
});
}))

请注意,您没有随ajax请求提交任何文件,它与表单完全没有关联


还要注意,这在IE<10

中不起作用,我的问题由您的向导解决。非常感谢你的好朋友
$('form').submit(function() {
    var numberOfFilesAboutToBeSubmitted = $("[name='file[]']", this ).prop("files").length;