Php 尝试通过Ajax上载文件时无法处理的实体
我刚刚把我的本地代码移到了live server。一切正常,但当我尝试在live server上上载图像时,出现“无法处理的实体”错误。文件上传在我的本地服务器上运行良好。我正在使用Windows server和IIS以及PHP7.2,我的项目使用的是Laravel5.5 我已尝试为IUSER和IIS_IUSR授予完全控制权限。我还尝试更新php.ini文件(file\u uploads=On,upload\u max\u filesize=20M,post\u max\u size=20M) 我的表格Php 尝试通过Ajax上载文件时无法处理的实体,php,laravel,iis-10,Php,Laravel,Iis 10,我刚刚把我的本地代码移到了live server。一切正常,但当我尝试在live server上上载图像时,出现“无法处理的实体”错误。文件上传在我的本地服务器上运行良好。我正在使用Windows server和IIS以及PHP7.2,我的项目使用的是Laravel5.5 我已尝试为IUSER和IIS_IUSR授予完全控制权限。我还尝试更新php.ini文件(file\u uploads=On,upload\u max\u filesize=20M,post\u max\u size=20M)
<form class='form-inline' id='edit-property-image' enctype='multipart/form-data'>
<input type='hidden' id='property' value='$id' name='property'>
<input type='file' class='custom-file-input' id='propertyImage' name='propertyImage' onchange='propertyImageChange(this)'>
<a href='javascript:updatePropertyImage($id)' class='btn btn-primary'>Update Image</a>
</form>
控制器
$id=$request->input('property')
我解决了这个问题。这实际上是因为我的php.ini文件没有指定默认的临时文件夹。一旦我添加文件上传工作。我认为这是由于验证错误,因此,请检查浏览器中的laravel验证。同时根据“propertyImage”=>“image | max:1999 | required”检查文件大小不大于1999
function updatePropertyImage(id)
{
$.ajax({
data:new FormData($("#edit-property-image")[0]),
async:false,
type:'post',
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
method: 'POST', // Type of response and matches what we said in the route
url: '/property/updateImage', // This is the url we gave in the route
success: function(response){ // What to do if we succeed
if(response.response == "success") {
$('.modal').modal('hide');
propertyDetails(id);
}
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
alert(errorThrown);
}
});
}
$this->validate($request,[
'propertyImage' => 'image|max:1999|required'
]);
$response = "failed";
//Handle File Upload
if($request->hasFile('propertyImage')){
//Get Filename with extension
$fileNameWithExt = $request->file('propertyImage')->getClientOriginalName();
// Get just filename
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $request->file('propertyImage')->getClientOriginalExtension();
//Filename to store
$fileNameToStore = $id.'_'.time().'.'.$extension;
//Upload Image
$path = $request->file('propertyImage')->storeAs('public/property_images', $fileNameToStore);
$property = Property::find($id);
$property->image_url = $fileNameToStore;
$property->save();
$response = "success";
}
return response()->json([
'response' => $response,
]);