Advertisement
michaelyuen

Untitled

Jan 2nd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
  2. <script>
  3. tinymce.init({
  4.     file_browser_callback :
  5.     function(field_name, url, type, win){
  6.         var filebrowser = "yourfile.php?a=param";
  7.         filebrowser += (filebrowser.indexOf("?") < 0) ? "?type=" + type : "&type=" + type;
  8.         tinymce.activeEditor.windowManager.open({
  9.         title : "Insert File",
  10.         width : 700,
  11.         height : 400,
  12.         url : filebrowser
  13.         }, {
  14.         window : win,
  15.         input : field_name
  16.         });
  17.         return false;
  18.     }
  19. }
  20. </script>
  21.  
  22. // == yourfile.php ==
  23.  
  24. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  25. <script>
  26. $(document).on("click",".file",function(){
  27.   item_url = $(this).data("src");
  28.   var args = top.tinymce.activeEditor.windowManager.getParams();
  29.   win = (args.window);
  30.   input = (args.input);
  31.   win.document.getElementById(input).value = item_url;
  32.   top.tinymce.activeEditor.windowManager.close();
  33. });
  34. </script>
  35. <?php
  36. $path = 'yourimagefolder/';
  37. $files = GLOB($path.'*{.jpg,.png}',GLOB_BRACE);
  38. ?>
  39. <?php if (!EMPTY($files)): ?>
  40.     <ul style="display: inline-block; width: 100%; box-sizing: border-box; list-style: none; padding: 0;">
  41.     <?php foreach ($files as $file): ?>
  42.         <?php
  43.             $file_name = basename($file);
  44.             $file = str_replace(' ', '%20', $file);
  45.         ?>
  46.         <li class="file" data-src="<?= $path.$file_name; ?>" style="margin: 10px; width: 100px; display: inline-block; height: 100px; float: left; cursor: pointer;">
  47.             <div class="file_image" title="<?= $file_name; ?>" style="display: block; width: 100px; height: 100px; background-image: url(<?= $path.$file_name; ?>); background-position: center center; background-size: cover;"></div>
  48.         </li>      
  49.     <?php endforeach; ?>
  50.     </ul>  
  51. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement