How To Get Selected File From elFinder File Manger Window

elFinder is a great file manager to use to manage files on your web servers hard drive. It can be configured to work with TinyMCE or called on it’s own which is what I am going to demonstrate here. When browsing files I wanted to be able to select a file and then to get the URL of that file passed back to the main form.

elfinder

The default instance of elFinder doesn’t return the selected file to the previous window which is a bit of a pain, but thankfully it’s not all that hard to get it working. For this instance I was creating a form that would create an image gallery. Images were selected from the hard drive and then once submitted the selected images would become a gallery. So I needed to use elFinder as a file manager to browse the disk and allow me to upload new images.

The following HTML is setup to trigger the elFinder window and display any images that are selected. There is a hidden input field that will store the selected images you you can send them through in a form. The selected images will then be displayed in the “selectedImages” div after selecting them.

<input type = "text" name = "galleryimages" id = "galleryimages" style = "display:none"/>
<a href = "javascript:void(0)" id = "elfinder_button">Add Gallery Images</a>
<div id = "selectedImages">

</div>

The javascript below is set to wait for a click of the href. Once clicked it will display the window. The url will need to be changed if you have “connector.php” moved to a different location. I found height and width useful to, but they are optional. Place any code you like inside “getFileCallback”. You can use jQuery to put the “file” value anywhere you like on your page.

$('#elfinder_button').live('click', function() {
  $('<div id="editor" />').dialogelfinder({
    url : 'php/connector.php',
    width: '80%',
    height: '600px',
    getFileCallback: function(file) {
      var filePath = file; //file contains the relative url.
      var imgPath = "<img src = '"+filePath+"'/>";
      $('#selectedImages').append(imgPath); //add the image to a div so you can see the selected images
      $('#editor').remove(); //close the window after image is selected
    }
  });
});

I found I had to update some of the CSS for the elFinder window as the buttons were showing up strange. I was able to add the CSS to the page that was calling the file manager so there was no issues fixing this.

Related Articles

Related Questions

Should I Be Concerned About Suspicious Connection Attempts from Cloudflare?

I've been getting a lot of notifications from my Netgear RS300 about "Suspicious connection blocked". Over the past 72 hours, I've noticed around 15...

Why can’t I access a specific website on my Mac?

I'm having trouble opening the website www.bitwig.com on my Mac running Ventura 13.7.5. I've visited this site multiple times without issues, but now it...

What’s the Best Way to Reset My Samsung Smart TV?

I've been enjoying my Samsung Smart TV from around 2020, but recently it's been acting up with random app crashes, input lag, and sound...

5 COMMENTS

  1. First thanks this was very helpful.

    I would be helpful to list the js and css libraries required:

    jquery.min.js
    jquery-ui.min.js
    smoothness/jquery-ui.min.css
    elfinder.min.js

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

OpenAI Token Calculator

This tool is a simple OpenAI token calculator, web-based utility designed to help you quickly estimate the number of tokens in your text when...

List Sorting Tool

Welcome to our innovative list ordering and management tool. This next-level platform enables you to sort a list of items in ascending or descending...

Sudoku Solver

Welcome to our free online Sudoku solving tool, an interactive platform for puzzle enthusiasts seeking a break from a Sudoku conundrum. This advanced platform...

Apply Image Filters To Image

Digital imagery in the modern world is all about reinforcing emotions and stories behind each photo we take. To amplify this storytelling, we are...

Add Watermark To Image

As the world is increasingly consumed by digital media, protecting your original images is paramount. We are thrilled to introduce you to our innovative...

CSV To Xml Converter

Welcome to our CSV to XML converter tool, a convenient and user-friendly solution for all your data conversion needs. This versatile tool on our...

Latest Posts

Latest Questions