Using Php+mcdropdown to implement file paths you can select _php in the dropdown box

Source: Internet
Author: User
Keywords PHP File path drop-down box
The recent use of PHP file directory information read, online to get the following code:
Gets the list of files in the specified directory
$path The specified directory, default to the current directory
$ifchild whether to display a list of subdirectory files, which are not displayed by default
$curpath Displays the current path, which is the default starting from the current directory; This is primarily to show the determination of the HREF path
Copy CodeThe 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 the display subdirectory is set
{
Recursive
Openpath ($path. Directory_separator. $file, $ifchild, $curpath. Directory_separator. $file);
}
Else
{
echo "
  • $file
  • \ n ";
    }
    }
    else if ($file! = basename (__file__))//Exclude Current execution script
    {
    echo "
  • $file
  • \ n ";
    }
    Else
    {
    Echo $file;
    }
    }
    }
    }
    Closedir ($handle);
    }

    Because you want to provide the function of path selection, it is best to have a drop-down menu, which is left to select the path to display, so much more convenient, so they changed, the path output into an unordered list.
    Here is a code that gets the path of all the child files under the current file:
    Copy CodeThe code is as follows:
    /* Get a list of specified directory file paths
    * $path The specified directory, default to the current directory
    * $ifchild whether to get a list of subdirectory files, which is not acquired by default
    * $curpath Displays the current path, which defaults to starting from the current directory
    *& $pach _html_srt to pass in a reference to an external variable, because this method might be called recursively, so save it in this way
    * Some information can also be implemented with global variables, and changes in the function internal variables also affect the external.
    *& $path _ref_count principle, a count flag, if recursive, the counter from the last saved value from the beginning of the increment
    */
    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)
      {
      Recursive
      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 plugin in the foreground to allow the user to select the desired directory through the drop-down menu, so it needs to be encapsulated in the specified format:
    Copy CodeThe 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);

      So I spread the $path_html_str to the foreground, showing a list of unordered lists that meet the requirements of mcdropdown, and you can display the corresponding list of options.
      The complete code is as follows:
      test.html
      Copy CodeThe code is as follows:




      <title>Test</title>










      Please select a Category:



      #categorymenu #



      test.php
      Copy CodeThe code is as follows:
      Directory Information Processing
      $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);
        Var_dump ($path _info);
        Var_dump ($path _html_str);
        $str _buffer = file_get_contents (dirname (__file__). Directory_separator. ' test.html ');
        $str _buffer = Str_replace ("#categorymenu #", $path _html_str, $str _buffer);
        $str _buffer = Str_replace ("#delim #", Directory_separator, $str _buffer);
        echo $str _buffer;
        /* Get a list of specified directory file paths
        * $path The specified directory, default to the current directory
        * $ifchild whether to get a list of subdirectory files, which is not acquired by default
        * $curpath Displays the current path, which defaults to starting from the current directory
        *& $pach _html_srt to pass in a reference to an external variable, because this method might be called recursively, so save it in this way
        * Some information can also be implemented with global variables, and changes in the function internal variables also affect the external.
        *& $path _ref_count principle, a count flag, if recursive, the counter from the last saved value from the beginning of the increment
        */
        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)
          {
          Recursive
          Openpath ($path. Directory_separator. $file, $ifchild,& $path _html_str,& $path _ref_count);
          }
          $path _html_str.= '
      • ';
        }
        }
        }
        }
        Closedir ($handle);
        }
        ?>

        The jquery Mcdropdown plugin can be downloaded here: http://www.givainc.com/labs/mcdropdown_jquery_plugin.htm
      • Related Article

        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.