0
summernote Image Upload에 문제가 있습니다. 나는 summernote가 이미지를 base64로 변환하고 제출하면 이미지를 백엔드 데이터베이스 서버에 직접 저장한다는 것을 알고 있습니다. 서버 폴더에 이미지를 업로드하는 몇 가지 코드가 있습니다.하지만 그것은 나를 위해 작동하지 않습니다 ... 친구 도와주세요.summernote vue html 편집기가 서버에 이미지를 업로드하지 않습니다.
내 스크립트입니다 :
$(function() {
$('.summernote').summernote({
height: 200,
onImageUpload: function(files, editor, editable) {
sendFile(files[0],editor,editable);
}
});
function sendFile(file,editor,welEditable) {
data = new FormData();
data.append("file", files);
$.ajax({
url: "uploader.php",
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
$('.summernote').summernote("insertImage", data, 'filename');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus+" "+errorThrown);
}
});
}
});
Uploader.php
<?php
if ($_FILES['file']['name']) {
if (!$_FILES['file']['error']) {
$name = md5(rand(100, 200));
$ext = explode('.', $_FILES['file']['name']);
$filename = $name . '.' . $ext[1];
$destination = 'images/content/' . $filename; //change this directory
$location = $_FILES["file"]["tmp_name"];
move_uploaded_file($location, $destination);
echo 'http://localhost/ . $filename;//change this URL
}
else
{
echo $message = 'Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
?>