加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – TinyMCE为图片网址添加额外的斜杠

发布时间:2020-12-13 21:40:04 所属栏目:PHP教程 来源:网络整理
导读:我正在为一个客户建立的新网站上测试tinyMCE. 这是编辑器的测试页面…… http://simplicity.s462.sureserver.com/editor.php 我遇到的问题是当我进行图像插入并选择其中一个图像时,tinyMCE会在图像网址上添加一个额外的斜杠.结果,找不到图像.当我手动删除额
我正在为一个客户建立的新网站上测试tinyMCE.

这是编辑器的测试页面……

http://simplicity.s462.sureserver.com/editor.php

我遇到的问题是当我进行图像插入并选择其中一个图像时,tinyMCE会在图像网址上添加一个额外的斜杠.结果,找不到图像.当我手动删除额外的斜杠时,会找到图像.

如何防止tinyMCE添加这些额外的斜杠?我确信有一个简单的答案,但我一直在寻找几个小时,我没有找到答案的运气.我究竟做错了什么??

以下是用于填充图像列表的PHP代码:

<?php // this must be the very first line in your PHP file! 

// You can't simply echo everything right away because we need to set some headers first! 
$output = ''; // Here we buffer the JavaScript code we want to send to the browser. 
$delimiter = ""; // for eye candy... code gets new lines 

$output .= 'var tinyMCEImageList = new Array('; 

$directory = "../../images"; // Use your correct (relative!) path here 

// Since TinyMCE3.x you need absolute image paths in the list... 
$abspath = preg_replace('~^/?(.*)/[^/]+$~','/$1',$_SERVER['SCRIPT_NAME']); 

if (is_dir($directory)) { 
    $direc = opendir($directory); 

    while ($file = readdir($direc)) { 
        if (preg_match('~^.~',$file)) { // no hidden files / directories here... 
             if (is_file("$directory/$file") && getimagesize("$directory/$file") != FALSE) { 
                // We got ourselves a file! Make an array entry: 
                $output .= $delimiter 
                    . '["' 
                    . utf8_encode($file) 
                    . '","' 
                    . utf8_encode("$abspath/$directory/$file") 
                    . '"],'; 

            } 
        } 
    } 

    $output = substr($output,-1); // remove last comma from array item list (breaks some browsers) 
    $output .= $delimiter; 

    closedir($direc); 
} 
else
{
    echo "false";
}

// Finish code: end of array definition. Now we have the JavaScript code ready! 
$output .= ');'; 

// Make output a real JavaScript file! 
header('Content-type: text/javascript'); // browser will now recognize the file as a valid JS file 

// prevent browser from caching 
header('pragma: no-cache'); 
header('expires: 0'); // i.e. contents have already expired 

// Now we can send data to the browser because all headers have been set! 
echo $output; 

?>

以下是TinyMCE的设置:

// General options 
    mode : "textareas",theme : "advanced",plugins : "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",// Theme options 
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",theme_advanced_buttons2 : "cut,copy,pastetext,pasteword,search,replace,bullist,numlist,outdent,indent,blockquote,undo,redo,link,unlink,anchor,image,cleanup,help,code,insertdate,inserttime,forecolor,backcolor",theme_advanced_buttons3 : "tablecontrols,hr,removeformat,visualaid,sub,sup,charmap,ltr,rtl,fullscreen",theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,styleprops,spellchecker,cite,abbr,acronym,del,ins,attribs,template,insertfile,insertimage",theme_advanced_toolbar_location : "top",theme_advanced_toolbar_align : "left",theme_advanced_statusbar_location : "bottom",theme_advanced_resizing : true,relative_urls : false,convert_urls : false,// Example content CSS (should be your site CSS) 
    content_css : "css/example.css",// Drop lists for link/image/media/template dialogs 
    template_external_list_url : "js/template_list.js",external_link_list_url : "js/link_list.js",external_image_list_url : "external_image_list_url.php",media_external_list_url : "js/media_list.js",

谢谢你的帮助!!

解决方法

以下是tinymce网站的几个例子.

他们用额外的../../斜线解决了我遇到的问题.

绝对URL

tinymce.init({
    relative_urls: false
});

具有主机名的绝对URL.

tinymce.init({
    relative_urls: false,remove_script_host: false
});

相对网址

tinymce.init({
    relative_urls: true
});

URL相对于给定页面.

tinymce.init({
    selector: '#relurlstopage',relative_urls: true,document_base_url: 'http://www.tinymce.com/tryit/'
});

不要转换URL

tinymce.init({
    plugins: 'link image code',convert_urls: false
});

资料来源:http://www.tinymce.com/tryit/url_conversion.php

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读