0 レビュー
1 回答
javascript-summernoteアップロード画像:onImageUploadおよびsendFile関数が機能しない
summernotev0.8.12を使用しています
サマーノート付きの私のページ:
<!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ファイル-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フォームのテキストエリアに何も表示されていないため、summernoteページはeditor-upload2.phpファイルに情報を渡していないようです。
助けていただければ幸いです。
これを読んでくれてありがとう。
わからない
0
レビュー
答え :
解決策:
メインページのヘッダーにある次のスクリプトが機能を停止していました:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
URLから「slim」を削除しましたが、正常に機能するようになりました
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。