<?php
$carpeta_ficheros = 'uploads/';
$directorio = opendir($carpeta_ficheros); // Opens Folder
while ($fichero = readdir($directorio)) { // reads every file
  if (!is_dir($fichero)){ // Omits the folders
echo "<div class='fichero' data-src='".$carpeta_ficheros.$fichero."'>".$fichero."</div>";
}
}
?>
<script type="text/javascript" language="javascript">
$(document).on("click","div.fichero",function(){
  item_url = $(this).data("src");
  var args = top.tinymce.activeEditor.windowManager.getParams();
  win = (args.window);
  input = (args.input);
  win.document.getElementById(input).value = item_url;
  top.tinymce.activeEditor.windowManager.close();
});
</script>


?>