如何使用jQuery将输入的pdf文件上传到php? [英] How to upload a pdf file from input with jquery to php?

查看:160
本文介绍了如何使用jQuery将输入的pdf文件上传到php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用向导来完成系统上的用户配置文件.在第7步中,我使用向导加载pdf文档.我希望从插补中选择文档时自动加载,但是我遇到了以下麻烦.

I am using a wizard to complete a user profile on my system. In step 7, I use the wizard to load a pdf document. I want the document to load automatically when selected from the imput, but I am having the following complications.

值得一提的是,我想用ajax加载它(这样该过程是自动的)并将其发送到php以将其保存在服务器上.

It is worth mentioning that I want to load it with ajax (so that the process is automatic) and send it to php to save it on the server.

向导是这样的(作为参考): https://jsfiddle.net/yeyene/59e5e1ya/

The wizard is this (as reference): https://jsfiddle.net/yeyene/59e5e1ya/

我的输入:

<div class="box">
    <input type="file" name="file-7" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple />
        <label for="file-7">
            <span></span> 
            <strong>
                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/>
                </svg> 
                Find pdf &hellip;
            </strong>
        </label>
</div>

这是我的js

$('#file-7').change(function(e){
    var file_data = this.files[0];
    //var file_data = $(this).prop('files')[0];
    console.log(file_data);
        if(file_data != undefined) {
            var datos = new FormData();
            datos.append('sendpdf', true);                  
            datos.append('pdf', file_data);
            $.ajax({
                url:"views/ajax.php",
                method:"POST",
                data:datos,
                contentType:false,
                processData:false,
                beforeSend: function() {
                    $("#loading").removeClass('hidden');
                },
                success: function(regreso){
                    $("#loading").addClass('hidden');

                    console.log(regreso);
                }
            });
        }  
});

这是我的ajax.php

This is my ajax.php

if (isset($_POST["sendpdf"])) {
    var_dump($_POST['pdf']);
}

错误:

console.log(file_data);

感谢我的帮助.

推荐答案

仅我需要在php中接收以下代码:

Only I need receive in php with these code:

$_FILES['file']

这篇关于如何使用jQuery将输入的pdf文件上传到php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆