为什么500(内部服务器错误)?
我上传图片的路线
Route::post('tech-img', 'ImageController@imageCropPost');
我的控制器用于上传图片
public function imageCropPost(Request $request)
{
$data = $request->image;
$id=$request->id;
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
$image_name= time().'.png';
$path = public_path() . "/upload/" . $image_name;
file_put_contents($path, $data);
$update=DB::table('technologys')
->where('id','=', $id)
->update(['img' => $image_name]);return $update;}`
我的Ajax上传图片
function uptecimage(id){
var id=id.id;
$('#inputimg').val(id);}
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
$('.upload-result').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (resp) {
var id= document.getElementById('inputimg').value;
$.ajax({
url: "/tech-img",
type: "POST",
data: {"image":resp, "id":id},
success: function (data) {
console.log(data);
/*
html = '<img src="' + resp + '" />';
$("#upload-demo-i").html(html);
*/
}
});
});
});
我的刀片Templet或用于上传图片的HTML代码
<button data-toggle="modal" href='#upimage' onclick="uptecimage(this)" id="{{$tech->id}}"><i class="fa fa-camera"></i></button>
<div class="modal fade" id="upimage">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Image Upload</h4>
</div>
<div class="modal-body">
<input type="hidden" name="inputimg" id="inputimg" class="form-control" value="">
<div id="upload-demo" style="width:350px"></div>
<strong>Select Image:</strong>
<br/>
<input type="file" id="upload">
<br/>
<button class="btn btn-success upload-result">Upload Image</button>
</div>
</div>
</div>
</div>
按下“上传图像”按钮时出现错误无法加载资源:服务器的状态为500(内部服务器错误)