Dropzone image uploaded problem
when i uploaded image using dropzone plugin it's through a 500 internal server error.how can i fixed it?please help me. Thank you.
If you don't show your code, nobody will be able to help you.
@vincent15000
here is my controller
class TempImageController extends Controller
{
public function create(Request $request)
{
$image = $request->image;
if(!empty($image)){
$ext = $image->getClientOriginalExtention();
$newName = time().'.'.$ext;
$tempImage = new TempImage();
$tempImage->name = $newName;
$tempImage->save();
$image->move(public_path('temp'),$newName);
return response()->json([
'status' => 'true',
'image_id' => $tempImage->id,
'message' => 'Image uploaded successfully'
]);
}
}
}
@vincent15000
Here is the script
Dropzone.autoDiscover = false;
const dropzone = $("#image").dropzone({
init: function() {
this.on('addedfile', function(file) {
if (this.files.length > 1) {
this.removeFile(this.files[0]);
}
});
},
url: "{{ route('temp-images.create') }}",
maxFiles: 1,
paramName: 'image',
addRemoveLinks: true,
acceptedFiles: ".jpeg,.jpg,.png,.gif",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}, success: function(file, response){
$("#image_id").val(response.image_id);
console.log(response)
}
});
check your server laravel logs to see what the error was
Check your $request also.
Please or to participate in this conversation.