使用AJAX将PDF文件发送到服务器(PHP LARAVEL) [英] Sending PDF file to server (PHP LARAVEL) using AJAX
问题描述
我正在尝试将AJAX的文件(PDF)上传到我的服务器,以由laravel项目中的php脚本处理.我无法在服务器上发送和接收文件.
I am trying to upload a file (PDF) by AJAX to my server to be handled by a php script in a laravel project. I cannot get the file to send and be received on the server.
在网络中,我可以看到POST请求收到200响应,但是它返回的响应是文件不存在" ,这是laravel的响应.
In the network I can see that the POST request is getting a 200 response, however it is returning a response of 'file not present', which is the response from laravel.
还在发布请求中,请求有效载荷包含以下内容
Also in the post request the Request Payload contains the following
------WebKitFormBoundaryliAmA3wxs0bB32iZ--
请参见下面的js,html和php
Please see the js and html and php below:
html
<form enctype="multipart/form-data">
<input type="file" id="cv" name="cv"/>
<button id="file-send">Add</button>
</form>
js
$('#file-send').bind('click', function () {
$.ajax({
url:"test",
data: new FormData($("#cv")[0]),
type:'POST',
processData: false,
contentType: false,
success:function(response){
console.log(response);
},
});
});
LARAVEL密码
public static function uploadingFile(){
if (Input::hasFile('cv'))
{
return "file present";
}
else{
return "file not present";
}
推荐答案
尝试使用此插件上传文件
Try This Plugin to upload file
http://malsup.com/jquery/form/#file-upload
var options = {
beforeSubmit: showRequest,
success: showResponse,
dataType :'json'
};
$('#file-send').ajaxSubmit(options);
function showRequest()
{
//before uploading file
}
function showResponse()
{
//response after uploading file
}
这篇关于使用AJAX将PDF文件发送到服务器(PHP LARAVEL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!