即使在尝试上传文件后,UploadHandle也始终不返回任何文件?

时间:2018-01-09 05:18:03

标签: javascript php jquery-file-upload

我正在尝试上传文件,但是,它总是似乎永远不会将文件发送到服务器,即使没有错误或文件上传报告失败。

我尝试使用分块,文件大小,并不断检查服务器上的文件夹,看它是否可用。

  

“文件不在服务器上......”

现在是始终返回的消息框, /inf/uploadhandle/index.php  确实存在,因为我能够在浏览器中使用该直接链接始终返回

{"files":[]}

HTML

<form action="/inf/fileuploadxx.php" method="post" enctype="multipart/form-data">
<h2>Upload: </h2>
<input type="file" id="fileuploadx" name="filex" data-url="/inf/uploadhandle/index.php">
<br>
<div id="progressfile" style="width:100%; background:black;display:none;";>
    <div class="bar" style="width: 0%; height: 18px; background: green;}">
    </div>
</div>
<div id="progressfiletext">
</div>
<br><br>
<br><br>
<h2 id="waitsubmit">waiting for approved file...</h2>
<input id="truesubmit" type="submit" class="btn" value="Continue" name="submit" style="align-self:center;display:none;">

的Javascript

<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script src="js/jquery.fileupload-process.js"></script>
<script src="js/jquery.fileupload-validate.js"></script>
<script>
$(function () {
    $('#fileuploadx').fileupload({
        url: '/inf/uploadhandle/index.php',
        dataType: 'json',
        autoUpload:true,
        maxNumberOfFiles:1,
        //maxFileSize: 1200000000, // 120 MB
        //maxChunkSize: 10000000, // 10 MB
        add: function (e, data) {
            $("#fileuploadx").css('display','none');
            $("#progressfile").show();
            $("#progressfiletext").text("Uploading...");

            data.submit();
            console.log("uploading request! ");
            console.log(e);
            console.log(data);
        },
        done: function (e, data) {
            $("#waitsubmit").hide();
            $("#truesubmit").show();
            var x=0;
            $.each(data.result.files, function (index, file) {
                $("#progressfiletext").text(file.name);
                x++;
            });
            if (x==0){
                $("#progressfiletext").text("File isn't on server...");
                $("#progressfile .bar").css('background','red');
            }
            console.log("upload pass!");
            console.log(e);
            console.log(data);
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progressfile .bar').css(
                'width',
                progress + '%'
            );
            if (progress > 99) {
                $("#progressfiletext").text("Pushing file through Cloudflare, may take a little bit more.");
            }
            $("#progressfiletext").text("Uploading... ("+progress + '%'+")");
        },
        fail: function (e, data) {
            console.log("fail...");
            console.log(e);
            console.log(data);
            $("#progressfiletext").text("Failed upload.");
            $("#progressfile .bar").css('background','red');
        },
        error: function (e, data) {
            console.log("error....");
            console.log(e);
            console.log(data);
            $("#progressfiletext").text("Failed upload.");
            $("#progressfile .bar").css('background','red');
        }
    });
    $('#fileuploadx').bind('fileuploadprocessfail', function (e, data) {
        alert(data.files[data.index].error);
    });
});
</script>

修改 我已将以下PHP添加到/inf/fileuploadxx.php到

<?php
error_reporting(1);
echo "<br>type?:" . $_SERVER["CONTENT_TYPE"];
echo "<br>method:" . $_SERVER["REQUEST_METHOD"];

echo '<br><br><br><br>';
if($_POST) {
    $allowed = array('png');

    if(isset($_FILES['filex']) && $_FILES['filex']['error'] == 0){

        $extension = pathinfo($_FILES['filex']['name'], PATHINFO_EXTENSION);

        if(!in_array(strtolower($extension), $allowed)){
            echo 'bad extension error ;(';
        }

        //if(move_uploaded_file($_FILES['filex']['tmp_name'], "/secure/" . $extension)){
            echo 'yaaaaaaaaaaay';
        //}
        //echo 'upload error ;( end';
    } else {
        echo 'upload error ;( fileerror';
        echo '<br>xxx>' . isset($_FILES['filex']);
        echo '<br>yyy>' . $_FILES['filex']['error'];
    }
} else {
    echo 'nopost';
}

输出为

  

上传错误;(fileerror

     

XXX→1

     

YYY→4

0 个答案:

没有答案