TinyMCE版本:4.6.5
我的表单和tinyMCE编辑器正在“public_html/adm”方向工作,我试图将图像上传到“public_html/images/upload”。
tinyMCE初始化
tinymce.init({
selector: '.mytextarea',
plugins: 'advlist autolink link lists charmap print preview media textcolor hr table image code powerpaste',
toolbar: 'undo redo | insert | styleselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent hr | link image table code ',
powerpaste_word_import: "prompt",
menubar: false,
min_height: 300,
entity_encoding : "raw",
// enable title field in the Image dialog
image_title: true,
// enable automatic uploads of images represented by blob or data URIs
automatic_uploads: true,
// URL of our upload handler (for more details check: https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_url)
images_upload_url: 'postAcceptor.php',
// here we add custom filepicker only to Image dialog
file_picker_types: 'image',
.
.
.
postAcceptor.php
<?php
$imageFolder = "../images/upload/";
reset ($_FILES);
$temp = current($_FILES);
if (is_uploaded_file($temp['tmp_name'])){
if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
header("HTTP/1.0 500 Invalid file name.");
return;
}
if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) {
header("HTTP/1.0 500 Invalid extension.");
return;
}
$filename = md5(date('YmdHis')).'.jpg';
$file = $imageFolder.$filename;
move_uploaded_file($temp['tmp_name'], $file);
echo json_encode(array('location' => $file));
} else {
header("HTTP/1.0 500 Server Error");
}
?>
在我上传我的图像后,它会像这样附加在文本区域上。
<p><img title="logo.png" src="../images/upload/0a13617f5d569df6c616578df855c92a.jpg" alt="" width="335" height="292" /></p>
问题是我的图像是不正确的渲染,除非我改变图像路径像这样。
<img title="logo.png" src="../../images/upload/0a13617f5d569df6c616578df855c92a.jpg" alt="" width="335" height="292" />
2条答案
按热度按时间z9smfwbn1#
您可以使用
images_upload_base_path
配置选项来预挂从已配置的images_upload_url
返回的URL:https://www.tiny.cloud/docs-4x/configure/file-image-upload/#images_upload_base_path
v1l68za42#
您可以使用
convert_urls: false,
选项。这将阻止添加../
。例如,tinyMCE init看起来像这样:
来源:https://www.tiny.cloud/docs/configure/url-handling/#convert_urls