In my console when the Upload button is not working i get 405 Method Not Allowed
May 9, 2020
27
Level 4
Can someone help me out
I am trying to upload, crop then save my image to my database. The problem i have is the upload button is not wotking. and when i get it to work, it doesn't send data to the controller.
<html>
<head>
<title>Test Test</title>
<script src="{{asset('js/jquery.min.js')}}"></script>
<script src="{{asset('js/bootstrap.min.js')}}"></script>
<script src="{{asset('js/croppie.js')}}"></script>
<link rel="stylesheet" href="{{asset('css/bootstrap.min.css')}}" />
<link rel="stylesheet" href="{{asset('css/croppie.css')}}" />
</head>
<body>
<div class="container">
<br />
<h3 align="center">Image Crop & Upload using JQuery with PHP Ajax</h3>
<br />
<br />
<div class="panel panel-default">
<div class="panel-heading">Select Profile Image</div>
<div class="panel-body" align="center">
<input type="file" name="upload_image" id="upload_image" accept="image/*" />
<br />
<div id="uploaded_image"></div>
</div>
</div>
</div>
</body>
</html>
<div id="uploadimageModal" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Upload & Crop Image</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-8 text-center">
<div id="image_demo" style="width:350px; margin-top:30px"></div>
</div>
<div class="col-md-4" style="padding-top:30px;">
<br />
<br />
<br/>
<button class="btn btn-success crop_image">Crop & Upload Image</button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$image_crop = $('#image_demo').croppie({
enableExif: true,
viewport: {
width:200,
height:200,
type:'square' //circle
},
boundary:{
width:300,
height:300
}
});
$('#upload_image').on('change', function(){
var reader = new FileReader();
reader.onload = function (event) {
$image_crop.croppie('bind', {
url: event.target.result
}).then(function(){
console.log('jQuery bind complete');
});
}
reader.readAsDataURL(this.files[0]);
$('#uploadimageModal').modal('show');
});
$('.crop_image').click(function(event){
$image_crop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function(response){
$.ajax({
url:"/profile",
type: "POST",
data:{"image": response},
success:function(data)
{
$('#uploadimageModal').modal('hide');
$('#uploaded_image').html(data);
}
});
})
});
});
</script>
Level 33
Have you tried using the Storage facade instead?
$fileName = 'public/avatars/' . $imageName;
Storage::disk('local')->put($fileName, $data);
That will put the file in the storage/app/public/avatars folder.
Remember to reference the facade at the top of your controller like this:
use Illuminate\Support\Facades\Storage;
Good luck
1 like
Please or to participate in this conversation.