Hello, This ia a code from Kcfinder function openKCFinder(div) { window.KCFinder = { callBack: function(url) { window.KCFinder = null; div.innerHTML = '<div style="margin:5px">Loading...</div>'; var img = new Image(); img.src = url; img.onload = function() { // afbeelding en pad afbeelding div.innerHTML = '<img id="img" src="' + url + '" />'; var img = document.getElementById('img'); var o_w = img.offsetWidth; var o_h = img.offsetHeight; var f_w = div.offsetWidth; var f_h = div.offsetHeight; if ((o_w > f_w) || (o_h > f_h)) { if ((f_w / f_h) > (o_w / o_h)) f_w = parseInt((o_w * f_h) / o_h); else if ((f_w / f_h) < (o_w / o_h)) f_h = parseInt((o_h * f_w) / o_w); img.style.width = f_w + "px"; img.style.height = f_h + "px"; } else { f_w = o_w; f_h = o_h; } img.style.marginLeft = parseInt((div.offsetWidth - f_w) / 2) + 'px'; img.style.marginTop = parseInt((div.offsetHeight - f_h) / 2) + 'px'; img.style.visibility = "visible"; } } }; window.open('kcfinder/browse.php??lang=nl&type=files=files/public', 'kcfinder_image', 'status=0, toolbar=0, location=0, menubar=0, ' + 'directories=0, resizable=1, scrollbars=0, width=800, height=600' ); } Code (markup): The rule div.innerHTML = '<img id="img" src="' + url + '" />'; is the url from a chosen image if i am wright, is it posible this URL to put in a input field like, <input type="hidden" name="image_url" value="THe image URL" />
I use it with ckeditor and it's gives you the url. <script> function openKCFinder(field) { window.KCFinder = { callBack: function(url) { var id = field.target.id; $('#'+id).val(url); var preview = '#preview' + id.substr(12); console.log(id); console.log(preview); $(preview).attr('src', url); window.KCFinder = null; } }; window.open('https://www.mysite.org.nz/js/kcfinder/browse.php?type=images&langCode=en', 'kcfinder_textbox', 'status=0, toolbar=0, location=0, menubar=0, directories=0, ' + 'resizable=1, scrollbars=0, width=800, height=600' ); } </script> PHP:
Thanks but i must store the value off the image url in a input field so i can store it in the database table This is not with CKeditor https://kcfinder.sunhater.com/demos/image By the way: how to make the code in a code field on this forum (your code in black background)
the code I pasted was from a standalone use of kcfinder - you'll see in the callback it puts the url into a input and then sets the source on a preview image. I was in a hurry so dumped and ran without explaining, sorry. to wrap your code in bbcode use [ php ] and [/ php] but without the spaces.
I mean the IMAGE version https://kcfinder.sunhater.com/demos/image But there is no inputfield Is it posible the url to put in a value from a (hidden) inputfield after choose an image in the sourse off my webpage <div id="image" onclick="openKCFinder(this)"> <img id="img" src="/upload/files/myimage.jpg" style="width: 200px; height: 134px; margin-left: 0px; margin-top: 33px; visibility: visible;"/> </div> So how to copy /upload/files/myimage.jpg to a value off a input field
In my case it's identified here var id = field.target.id; $('#'+id).val(url); Code (markup): change $('#'+id) to whatever you've called your input field.
Thanks for help , file stuped as a beginner Can you give a better sample for the input how to do. <input type="hidden" value="" />
<input type="hidden" name="image_url" value="THe image URL" /> has nothing to do with the function you had posted. You have to make a form where to include this field and you get the url variable in the function as a function parameter so you should see where are you getting the url variable from and then include it in <input type="hidden" name="image_url" value="url" /> or you could make a global variable: var urlStringForHiddenFIeld; function openKCFinder(div) { window.KCFinder = { callBack: function(url) { urlStringForHiddenFIeld = url; } } } <input type="hidden" name="image_url" value="urlStringForHiddenFIeld" /> But in this case, you have to be sure that openKCFinder is called before the hidden field.