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

Looking for Feedback on Humanitec Use

Hey everyone! I'm diving into Humanitec and would love to hear from anyone who's actually using it. Specifically, I'm curious about the following: What...

What’s the Best Way to Host My Vite Website?

I've got Jenkins and Ansible configured to trigger deployments whenever I commit to my repo. This builds my Vite app and sends the generated...

Is a 10GB RTX 3080 still worth it in 2025?

My wife's GPU (a 1080 Ti) finally kicked the bucket, and I managed to snag a used setup with an i5-13600K, 32GB DDR5 RAM,...

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

xAI Grok Token Calculator

This tool is a simple xAI Grok token calculator that helps you estimate the number of tokens your input text might consume when working...

DeepSeek Token Calculator

This tool is a straightforward DeepSeek token calculator, created to help you estimate how many tokens your text may use when working with DeepSeek...

Google Gemini Token Calculator

This tool is a simple Google Gemini token calculator, designed to help you estimate how many tokens your text might use with models in...

Meta LLaMA Token Calculator

This tool is a basic Meta LLaMA token calculator, designed to give you a fast estimate of how many tokens your input text might...

Anthropic Claude AI Token Calculator

This tool is a simple Claude token calculator, built to help you quickly estimate token usage when working with Anthropic’s Claude models. It’s an...

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...

Latest Posts

Latest Questions