Ueditor call picture and attachment upload function

Source: Internet
Author: User
The code is as follows Copy Code

<! DOCTYPE html>
<title></title>
<script src= "Ueditor/ueditor.config.js" type= text/javascript "charset=" utf-8″></script>
<script src= "Ueditor/ueditor.config.js/ueditor.all.min.js" type= text/javascript "charset=" utf-8″></ Script>
<!–, of course, will also introduce jquery–>

var _editor;
$ (function () {
Re-instantiate an editor to prevent uploaded pictures or files from being displayed in the editor editor above
_editor = Ue.geteditor (' Myeditor ');
_editor.ready (function () {
The settings editor is not available
_editor.setdisabled ();
Hide the editor because this instance of the editor is not used, so hide
_editor.hide ();
Listening for picture uploads
_editor.addlistener (' Beforeinsertimage ', function (t, ARG) {
Assign the address to the corresponding input, only the path to the first picture
$ ("#pictrue"). attr ("value", ARG[0].SRC);
Picture preview
$ ("#picview"). attr ("src", "/public/" +arg[0][' src '));
});
Listen for file upload, take the path of the first uploaded file in the uploaded file list
_editor.addlistener (' Afterupfile ', function (t, ARG) {
var fileurl= "";
for (var i=0; i< arg.length i++) {//Implement multiple attachments upload. | split attachment Address
if (Arg[i].url = = undefined) {
Continue
}
if (i = = (arg.length-1)) {
fileurl=fileurl+ (ARG[I].URL.SUBSTR (9));
}else{
fileurl=fileurl+ (ARG[I].URL.SUBSTR (9)) + "| |"; //
}
}
$ ("#files"). attr ("value", FILEURL);
});
});
});
Pop-up Image Upload dialog box
function Upimage () {
var myimage = _editor.getdialog ("Insertimage");
Myimage.open ();
}
Pop-up File Upload dialog box
function Upfiles () {
var myfiles = _editor.getdialog ("attachment");
Myfiles.open (); Www.111cn.net
}
If you need to assign a value to a text box, you also need to 119 lines in the dialogs\attachment\attachment.html file Editor.execcommand ("inserthtml", str); previous line add Editor.fireevent (' Afterupfile ', fileslist);
Top of the program to achieve a multiple attachment upload, of course, you can refer to this modified multiple pictures upload
<body>
<script type= "Text/plain" id= "Myeditor" ></script>
<script type= "Text/plain" id= "Upload_ue" ></script>
Page to call:
<input type= "text" id= "picture" name= "cover"/><a href= "javascript:void (0);" onclick= "upimage ();" > Upload Pictures </a>
<input type= "text" id= "file"/><a href= "javascript:void (0);" onclick= "upfiles ();" > Upload file </a>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.