Tinymce图像上传php插件或其他东西

时间:2014-05-02 09:19:25

标签: javascript php image upload tinymce

我想上传图片形式本地并在textarea中显示...是否有一些免费插件,或者你能解释一下如何写一个?

我有以下代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
tinymce.init({
    selector: "textarea#elm1",
    theme: "modern",
    //width: 600,
    height: 300,
    file_browser_callback: function(field_name, url, type, win) {
        if(type=='image') $('.slike').click();
    },
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor ",
   ],
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ],
 }); 
</script>

这个代码在正文中:

<form id='my_form' action='' method='POST' enctype="multipart/form-data">
        Title:<br/>
        <input type='text' name='title'/><br/><br/>
        Content:<br/>
         <textarea id="elm1" name="area"></textarea>        
        <br/>
        <input class='slike' name="image[]" multiple="multiple" type="file">
        <input type='submit' name='submit' value='Ok!'/>
    </form>

1 个答案:

答案 0 :(得分:1)

几个星期前我遇到了同样的问题。

首先重要的是要关注tinymce textarea会显示像Web浏览器一样的图像和元素,因此您必须为href属性图像标签(外部发布的url o local url)输入正确的路径。

确保网址后,您将更改配置,以避免tinyMce控件从代码中删除图像标签。我通过这种配置得到了这一点(使用绝对路径):

tinyMCE.init({
    ...
    //your initialization rules
    ...
    // Drop lists for link/image/media/template dialogs
    template_external_list_url : 'lists/template_list.js',
    external_link_list_url     : 'lists/link_list.js',
    external_image_list_url    : 'lists/image_list.js',
    media_external_list_url    : 'lists/media_list.js',
    relative_urls              : false,
    remove_script_host         : false,
    convert_urls               : true,
    extended_valid_elements    : 'iframe[src|frameborder|style|scrolling|class|width|height|name|align]'
    });

我希望这段代码可以帮到你!!