Summernote Image Upload Not Working(PHP)
问题描述:
我已经尝试过在这里和其他地方找到的各种解决方案 - 最好是我将base64代码插入编辑器(我相信这是Summernote的默认设置),否则我什么也得不到。Summernote Image Upload Not Working(PHP)
我现在尝试的解决方案取自this post。
这里是我的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
</head>
<body>
<div id="summernote"></div>
<script>
$(document).ready(function() {
$('#summernote').summernote({
height: 200,
onImageUpload: function(files, editor, welEditable) {
sendFile(files[0], editor, welEditable);
}
});
function sendFile(file, editor, welEditable) {
data = new FormData();
data.append("file", file);
$.ajax({
data: data,
type: "POST",
url: "img-upload.php",
cache: false,
contentType: false,
processData: false,
success: function(url) {
editor.insertImage(welEditable, url);
}
});
}
});
</script>
</body>
</html>
这里的IMG-upload.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 = '/uploads/' . $filename; //change this directory
$location = $_FILES["file"]["tmp_name"];
move_uploaded_file($location, $destination);
echo 'http://<mydomain>/uploads/' . $filename;//change this URL
}
else
{
echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
?>
看起来像我有写权限的上传文件夹,任何人都可以看到这有什么不对吗?
答
的onImageUpload元素的一个回调元素,这里是你的代码:
$('#summernote').summernote({
height: 200,
callbacks: {
onImageUpload: function(files, editor, welEditable) {
sendFile(files[0], editor, welEditable);
}
}
});
你启用了错误报告?您是否收到任何错误 –
我在这里粘贴的代码是一切,唯一的错误报告是在上传脚本中,因为这是从Summernote脚本内部调用的,哪里会显示/记录错误? – Waloob73
我使用了一个警告框来测试Summernote是否调用sendFile函数,所以我知道这是被调用的,所以错误可能在PHP脚本中 – Waloob73