Use php + mcDropdown to implement the file path. select _ PHP in the drop-down box.

Source: Internet
Author: User
The following is a detailed analysis of the methods for selecting the file path of php + mcDropdown in the drop-down box. For more information, see Recently, I used php to read the file directory information and obtained the following code on the Internet:
// Obtain the file list in the specified directory
// $ Path specifies the directory. the default value is the current directory.
// $ Ifchild: whether to display the list of sub-directory files. it is not displayed by default.
// $ Curpath: displays the current path. the default value is from the current directory. this is mainly used to display the href path.
The code is as follows:
Function openpath ($ path = ".", $ ifchild = false, $ curpath = ".")
{

$ Handle = opendir ($ path );
If ($ handle)
{
While (false! ==( $ File = readdir ($ handle )))
{
If ($ file! = "." & $ File! = "..")
{
$ FullPath = $ path. DIRECTORY_SEPARATOR. $ file;
If (is_dir ($ fullPath) // if it is a directory file
{
If ($ ifchild) // if a subdirectory is set
{
// Recursion
Openpath ($ path. DIRECTORY_SEPARATOR. $ file, $ ifchild, $ curpath. DIRECTORY_SEPARATOR. $ file );
}
Else
{
Echo"
  • $ File
  • \ N ";
    }
    }
    Else if ($ file! = Basename (_ FILE _) // exclude the current execution script
    {
    Echo"
  • $ File
  • \ N ";
    }
    Else
    {
    Echo $ file;
    }
    }
    }
    }
    Closedir ($ handle );
    }

    Because you want to provide the path selection function, it is better to have a drop-down menu, which shows the paths to be selected. this is much more convenient, so you have changed the menu and output the paths into an unordered list.
    The following code retrieves the paths of all sub-files in the current file:
    The code is as follows:
    /* Get the list of file paths in the specified directory
    * $ Path specifies the directory. the default value is the current directory.
    * $ Ifchild: whether to obtain the list of subdirectory files. it is not obtained by default.
    * $ Curpath: displays the current path. the default value is from the current directory.
    * & $ Pach_html_srt transmits an external variable reference, because this method may be called recursively, so it is saved in this way.
    * Some information can also be implemented using global variables. variable changes within the function also affect the external.
    * & $ Path_ref_count the principle is the same as above. it is a counting sign. If recursion occurs, the counter is auto-incrementing from the last saved value.
    */
    Function openpath ($ path = ".", $ ifchild = false, & $ path_html_str, & $ path_ref_count)
    {
    $ Handle = opendir ($ path );
    If ($ handle)
    {
    While (false! ==( $ File = readdir ($ handle )))
    {
    If ($ file! = "." & $ File! = "..")
    {
    $ FullPath = $ path. DIRECTORY_SEPARATOR. $ file;
    If (is_dir ($ fullPath) // if the file is a directory
    {
    $ Path_html_str. ='
  • ';
    $ Path_html_str. = $ file .'
      ';
      If ($ ifchild)
      {
      // Recursion
      Openpath ($ path. DIRECTORY_SEPARATOR. $ file, $ ifchild, & $ path_html_str, & $ path_ref_count );
      }
      $ Path_html_str. ='
  • ';
    }
    }
    }
    }
    Closedir ($ handle );
    }

    With the above method, I can use the jquery mcDropdown plug-in the foreground to allow users to select the desired directory through the drop-down menu, so the directory needs to be encapsulated into the specified format:
    The code is as follows:
    $ Path_ref_count = 1;
    $ Path_html_str = '';
    Openpath (".", true, & $ path_html_str, & $ path_ref_count );
    $ Path_html_str ='
      '. $ Path_html_str .'
    ';
    $ Path_html_str = str_replace ("
      ",'', $ Path_html_str );

      In this way, I Upload $ path_html_str to the front-end. the displayed list is an unordered list that meets the mcDropdown requirements, and the corresponding list to be selected is displayed.
      The complete code is as follows:
      Test.html
      The code is as follows:




      Test

      Contact Us

      The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

      If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

      A Free Trial That Lets You Build Big!

      Start building with 50+ products and up to 12 months usage for Elastic Compute Service

      • Sales Support

        1 on 1 presale consultation

      • After-Sales Support

        24/7 Technical Support 6 Free Tickets per Quarter Faster Response

      • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.