[英]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.