提交更新后,Summernote 上传图像未显示在编辑器中
我一直在使用 Summernote 进行一个项目。我的项目就像一个博客系统,我需要上传内容和图像。
我已经检查了这里和其他地方的其他帖子,并设法使用 ajax 将图像插入到我想要保存图像的文件中。但是,当我编辑时,图像就在那里,但是一旦我单击“更新按钮”(表单中的提交按钮),图像将不再在那里。
我还检查了检查和资源,显示
请求 URL:http://localhost/cms/admin/includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG
这是正确的路径,但更新后,我收到类似
<强>请求网址: http://localhost/%22includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG/%22
状态代码还显示
状态代码:403禁止
这是我的代码
$('#summernote').summernote({
callbacks: {
onImageUpload: function(files) {
for(let i=0; i < files.length; i++) {
$.upload(files[i]);
}
}
},
height: 300,
});
$.upload = function (file) {
let out = new FormData();
out.append('file', file, file.name);
$.ajax({
method: 'POST',
url: './includes/editor-upload.php',
contentType: false,
cache: false,
processData: false,
data: out,
success: function(url) {
$('#summernote').summernote("insertImage", url, 'filename');
},
error: function (jqXHR, textStatus, errorThrown) {
console.error(textStatus + " " + errorThrown);
}
});
};
这是我的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 'includes/images/' . $filename;//change this URL
}
else
{
echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
将上传的图像插入summernote编辑器 Summernote 图片上传 Summernote 0.8.12图像上传和删除
我已经尝试过这些但对我来说没有任何作用。 我当然有 Summernote js 和 css 文件,并且正在使用 Summernote 0.8.18
我确信我做错了什么,但我还无法弄清楚这一点。
我希望有人能帮助我。
I have been working on a project, using Summernote. My project is like a blog system and I need to upload contents and images.
I have checked the other posts here and other places and managed to insert images to the file with ajax where I want to save the images. However, when I am editing, an image is there but once I click "update button" (submit button in a form), the images won't be there anymore.
I also check the inspect and resource says
Request URL: http://localhost/cms/admin/includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG
This is the right path but after updating, I get a message like
Request URL: http://localhost/%22includes/images/42a0e188f5033bc65bf8d78622277c4e.JPG/%22
Also status code says
Status Code: 403 Forbidden
Here is my code
$('#summernote').summernote({
callbacks: {
onImageUpload: function(files) {
for(let i=0; i < files.length; i++) {
$.upload(files[i]);
}
}
},
height: 300,
});
$.upload = function (file) {
let out = new FormData();
out.append('file', file, file.name);
$.ajax({
method: 'POST',
url: './includes/editor-upload.php',
contentType: false,
cache: false,
processData: false,
data: out,
success: function(url) {
$('#summernote').summernote("insertImage", url, 'filename');
},
error: function (jqXHR, textStatus, errorThrown) {
console.error(textStatus + " " + errorThrown);
}
});
};
And this is my php code (editor-upload.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 'includes/images/' . $filename;//change this URL
}
else
{
echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
Insert uploaded image to summernote editor
Summernote image upload
Summernote 0.8.12 Image Upload And Delete
I have tried these but nothing worked for me.
I have of course Summernote js and css file and am using Summernote 0.8.18
I am sure I am doing something wrong but I can't figure this out yet.
I am hoping somebody can help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果图像文件夹位于Inclusta Folder的内部,请更改以下行:
下一步
,输入完整的URL名称和通往图像的完整路径
回声'包括/images/'。 $ filename;
另外,AJAX上传脚本中的editor-upload.php文件可能会导致403错误。如果上传文件与您的表单和index.php页面不在同一文件夹中,则可能会证明有问题。
尝试使用夏季笔记编辑器将文件移至与您的表单相同的文件夹,然后在Ajax脚本中输入文件
'editor-upload.php'
If the images folder is inside of the includes folder, change the following line:
to
Next, enter the full URL name and the full path to the image instead of
echo 'includes/images/' . $filename;
Also, the editor-upload.php file in your Ajax upload script may be causing the 403 errors. if the upload file is not in the same folder as your form and index.php page, it can prove problematic.
Try moving the file to the same folder as your form with the summer note editor, and enter the file in your Ajax script as
'editor-upload.php'