dougaimian1143 2019-02-14 18:52
浏览 135

删除文件时$ _FILES为空,但不是单击

My JQuery populates $_FILES only when click on input type file but not when drop in a file.

All the examples, tutorials, documentation I have found is about using Ajax or pure JavaScript. None is what I want to do. I have found also plently of plugins, libraries, ... I just want to be able to drop a file.....

The FORM:

<form id="item-form" role="form" method="post" enctype="multipart/form-data">
    <div id="image-holder" class="dropBox">
        <img src="" style="width: 100%; padding: 10px;display: none;">
    </div>
    <div id="fileBox">
        <input type="file" name="image_file_input" id="image_file_input" />
    </div>
    <button type="submit" name="submit">SAVE</button>
</form>

The JQUERY:

$(".dropBox").on("drop", function(e) {
    e.preventDefault();
    e.stopPropagation();
    runUpload( e.originalEvent.dataTransfer.files[0] );
});
$(".dropBox").click(function(){
    $("#image_file_input").click();
});
$('input[type=file]').on('change', function(){
    runUpload( this.files[0] );
});
function runUpload( file ) {
    var reader = new FileReader(), image = new Image();
    reader.readAsDataURL( file );
    reader.onload = function( file ) {
        var image_holder = $("#image-holder");
        image_holder.empty();
        $("<img />", {
                        "src": file.target.result,
                        "class": ""
                    }).appendTo(image_holder);
        $("#dropBox").hide();
        $(image_holder).show();
}

The PHP:

if ( !empty($_FILES) ) {
    echo '---> Files not empty ';
}else{
    echo '---> Files empty ';
}

I don't want to use Ajax. I'm only showing the relevant part of the code to concentrate in the issue.

If I click on the dropBox or I drop a file (image) into the dropBox element I can see the image selected in the image_holder div.

When the form is submited if the file is from a click event it works perfectly but when is from a drop event $_FILES is empty.

I'm convinced the problem is what I pass to the runUpload function when dropping. I have tried all sort of things but unable to see what is wrong.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用