Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:20:44+00:00 2026-05-31T16:20:44+00:00

I am developing a component in J! 2.5 and want to add a browse

  • 0

I am developing a component in J! 2.5 and want to add a browse button on the backend so the user can pick a file they have previously uploaded. How would I go about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:20:45+00:00Added an answer on May 31, 2026 at 4:20 pm

    This is what I have come up with, if someone can make it more robust and reusable, that would be great. I may do it myself later, but for now I have an impossible deadline.

    loadDir.php:

    <?php
        if(isset($_GET['dir'])) {
            //Get array of valid extensions
            if(isset($_GET['ext'])) {
                if($_GET['ext'] == 'pdf') $validext = array("pdf");
                else $validext = array("jpg", "jpeg", "png", "gif");
            } else {
                $validext = array("pdf", "jpg", "jpeg", "png", "gif");
            }
            $root = dirname(dirname(dirname(getcwd()))) . "/";
            $directory = $root . $_GET['dir'];
            $files = scandir($directory);
            $thumb_count = 1;
            //make sure we haven't gone too high (should never be called)
            if(strpos($directory, 'images') == false) $directory = $root . "images";
    
            //TODO: sort array with dirs in front
    
            foreach($files as $file) {
                if ($file == '.') continue; //Remove current directory from loop
                //If in the images folder, don't let them go higher
                if ($file == '..' & $_GET['dir'] == 'images') continue;
                $path = $_GET['dir'];
                if($file == '..') {
                    $path = dirname($path);
                } else {
                    $path .= "/".$file;
                }
                if(is_dir($directory."/".$file)) {
                    echo "<a href=\"#\" onClick=\"loadDir('".$_GET['div']."', '".$path."', '".$_GET['ext']."'); return false;\">[DIR]".$file."</a>".PHP_EOL;
                } else {
                    //Check to see it's a valid extension
                    $ext = pathinfo($file, PATHINFO_EXTENSION);
                    $num = rand(0,100);
                    if(in_array($ext, $validext)) echo "<a href=\"#\" id=\"".$num."\" onClick=\"select(".$num.", '".$path."'); return false;\">[FILE]".$file."</a>".PHP_EOL;
                }
                if(($thumb_count % 5) == 0) echo "<br/>";
                $thumb_count++;
            }
        } else {
            echo "Error loading: Directory not available";
        }
    ?>
    

    administrator/components/com_XXX/views/XXX/tmpl/form.php:

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
            <script type="text/javascript">
                selected_file = "";
    
                function select(id, file) {
                    $('#' + id).css('background-color', 'red');
                    selected_file = file;
                }
    
                function loadDir(div, path, ext) {
                    $('#'+div+'Window').load('<?php echo JURI::root();?>administrator/components/com_lot/loadDir.php?div='+div+'&ext='+ext+'&dir='+path);
                }
    
                $(document).ready(function() {
                    $('#floorOpen').on("click", function(){
                        loadDir('floor', 'images', 'pdf');
                        $('#floorDialog').show();
                    });
    
                    $('#floorClose').on("click", function(){
                        $('#floorDialog').hide();
                        if(selected_file != "") $('#floor_plan').val(selected_file);
                        selected_file = "";
                    });
    
                    $('#floorCancel').on("click", function(){
                        $('#floorDialog').hide();
                        selected_file = "";
                    });
    
                    $('#mainOpen').on("click", function(){
                        loadDir('main', 'images', 'img');
                        $('#mainDialog').show();
                    });
    
                    $('#mainClose').on("click", function(){
                        $('#mainDialog').hide();
                        if(selected_file != "") $('#main_image').val(selected_file);
                        selected_file = "";
                    });
    
                    $('#mainCancel').on("click", function(){
                        $('#mainDialog').hide();
                        selected_file = "";
                    });
                });
            </script>
    
    ......
    
    <div id="floorDialog" style="position:absolute;display:none;width:400px;height:300px;border:1px solid #c0c0c0;background-color:#f0f0f0;top:800px;left:400px;">
            <div id="floorWindow" style="position:relative;width: 390px;height: 250px;margin: 4px;border: 1px solid #c0c0c0;">
            </div>
            <a href="#" onClick="return false;" id="floorCancel">Cancel</a><a href="#" onClick="return false;" id="floorClose">OK</a>
        </div>
        <div id="mainDialog" style="position:absolute;display:none;width:400px;height:300px;border:1px solid #c0c0c0;background-color:#f0f0f0;top:800px;left:400px;">
            <div id="mainWindow" style="position:relative;width: 390px;height: 250px;margin: 4px;border: 1px solid #c0c0c0;">
            </div>
            <a href="#" onClick="return false;" id="mainCancel">Cancel</a><a href="#" onClick="return false;" id="mainClose">OK</a>
        </div>
    
    ....
    
    <tr>
                <td width="100" align="right" class="key">
                    <label for="main_image">
                        <?php echo JText::_( 'Main Image' ); ?>:
                    </label>
                </td>
                <td>
                    <input class="text_area" type="text" name="main_image" id="main_image" size="32" maxlength="250" value="<?php echo $this->lotdata->main_image;?>" /><a href="#" onClick="return false;" id="mainOpen">Browse</a>
                </td>
            </tr>
            <tr>
                <td width="100" align="right" class="key">
                    <label for="floor_plan">
                        <?php echo JText::_( 'Floor Plan' ); ?>:
                    </label>
                </td>
                <td>
                    <input class="text_area" type="text" name="floor_plan" id="floor_plan" size="32" maxlength="250" value="<?php echo $this->lotdata->floor_plan;?>" /><a href="#" onClick="return false;" id="floorOpen">Browse</a>
                </td>
            </tr>
    

    Basically I use AJAX to get a formatted list of files/directories. Then, using javascript we select the file we want and output the path on dialog close.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a XPCOM C++ component that have to use some RegExps functions Does
I have been tasked with developing a Firefox add-on that is capable of registering
I am developing component and I want to know how to validate email value
I am developing a component that can list files that users select from their
I'm developing a flex application and I want to access a component by using
I'm now developing a component for Joomla 1.5. I want to update the header
I am working on developing a Chess game. I want to have the board
I'm developing a component in Joomla 1.6, is a Document Manager and I have
Hi I developing a common helper component for database access, so that one can
I'm developing a component (backend). I got a listview with a $_GET that contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.