weixin_33743703 2020-01-23 07:42 采纳率: 0%
浏览 50

$ _FILES没有值[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/4545081/how-to-do-file-upload-using-jquery-serialization" dir="ltr">how to do file upload using jquery serialization</a>
                            <span class="question-originals-answer-count">
                                (8 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/2320069/jquery-ajax-file-upload" dir="ltr">jQuery Ajax File Upload</a>
                            <span class="question-originals-answer-count">
                                (24 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2020-01-23 07:51:26Z" class="relativetime">3 months ago</span>.</div>
        </div>
    </aside>

First of all, I got this enctype="multipart/form-data" in my form tag.

When I send a data as a text, it proceeds and give me data.

<input type="text" class="form-control" name="attachment">

But when I change the type as "file", it don't send a data.

<input type="file" class="form-control" name="attachment">

Here is my HTML File:

<form id="form_attachment" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="employee_number" value="<?= $_GET[md5('employee_number')] ?>">

     <label class="bmd-label-floating">Choose Attachment</label>
     <input type="file" class="form-control" name="attachment">

     <label class="bmd-label-floating">Remarks</label>
     <textarea name="remarks" rows="5" class="form-control"></textarea>

     <input type="submit" id="btn_attachment" value="Insert" class="btn btn-info" style="float:right" /><br><br>
 </form>

AJAX:

$('#form_attachment').on("submit", function(e) {
    e.preventDefault();
    $.ajax({
        type: "POST",
        url: "../ajax/insert_attachment.php",
        data: $("#form_attachment").serialize(),
        beforeSend: function() {
        $('#btn_attachment').val("Updating");
    },
    success: function(response) {
        $('#form_attachment')[0].reset();
        $('#btn_attachment').val("Update");
        $('#modal_attachment').modal('hide');
        // $('#div_attachment').html(response);
        md.onboarding('bottom', 'right', response);
    }
    });
    e.preventDefault();
});

PHP:

$employee_number = $_POST['employee_number'];
$attachment = $_FILES["attachment"]["name"];
$attachment_tmp = $_FILES['attachment']['tmp_name'];
$remarks = $_POST['remarks'];

It gives me this error:

NOTICE: Undefined index: attachment in 
C:\XAMPP\HTDOCS\AJAX\INSERT_ATTACHMENT.PHP on line 6
NOTICE: Undefined index: attachment in 
C:\XAMPP\HTDOCS\AJAX\INSERT_ATTACHMENT.PHP on line 7
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料