[英]summernote upload image: onImageUpload and sendFile function not working
我正在使用 Summernote v 0.8.12
我的 Summernote 頁面:
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>bootstrap4</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.12/summernote-bs4.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.12/summernote-bs4.js"></script>
<script>
$(document).ready(function() {
$("#summernote").summernote({
placeholder: 'enter directions here...',
height: 300,
callbacks: {
onImageUpload : function(files, editor, welEditable) {
for(var i = files.length - 1; i >= 0; i--) {
sendFile(files[i], this);
}
}
}
});
});
function sendFile(file, el) {
var form_data = new FormData();
form_data.append('file', file);
$.ajax({
data: form_data,
type: "POST",
url: 'editor-upload2.php',
cache: false,
contentType: false,
processData: false,
success: function(url) {
$(el).summernote('editor.insertImage', url);
}
});
}
</script>
</head>
<body>
<form action="" method="post">
<input name="subject" class="form-control" />
<textarea id="summernote" name="body"></textarea>
<input name="button" type="submit" value="Submit" id="button">
</form>
</body>
</html>
用於上傳圖像的 php 文件 editor-upload2.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/' . $filename; //change this directory
$location = $_FILES["file"]["tmp_name"];
move_uploaded_file($location, $destination);
echo 'https://www.mysite.co.uk/folder/emails/' . $filename;//change this URL
}
else
{
echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
?>
似乎summernote頁面沒有將任何信息傳遞給editor-upload2.php文件,因為沒有上傳任何內容,並且summernote表單文本區域中也沒有出現任何內容。
任何幫助,將不勝感激。
非常感謝您閱讀本文。
主頁的 header 中的以下腳本停止了它的工作:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
我從 url 中取出“苗條”,現在可以正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.