- 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
- 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);
- }
Copy CodeBecause you want to provide the function of the path selection, if there is a drop-down menu, it is OK to select the path to display. 2. Obtain the code for all sub-file paths under the current file:
- /* 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);
- }
Copy CodeWith the above method, you can use the jquery Mcdropdown plugin in the foreground to allow the user to select the desired directory from the drop-down menu, so it needs to be encapsulated in the specified format:
- $path _ref_count = 1;
- $path _html_str = ";
- Openpath (".",true,& $path _html_str,& $path _ref_count);
- $path _html_str = "
;
- $path _html_str = Str_replace ("
", "", $path _html_str);
- ?>
Copy CodeThis $path_html_str to the foreground, which shows a list of unordered lists that meet the requirements of mcdropdown, and can display the corresponding list of choices. The complete code is as follows: 1, test.html
-
- jquery Mcdropdown implements a file path that can be selected in the dropdown box _bbs.it-home.org
-
-
-
- Please select a Category:
- #categorymenu #
-
-
Copy Code2, test.php
- Directory Information Processing
- $path _ref_count = 1;
- $path _html_str = ";
- Openpath (".",true,& $path _html_str,& $path _ref_count);
- $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);
- }
- ?>
Copy Codejquery mcdropdown plugin Download address: http://www.givainc.com/labs/mcdropdown_jquery_plugin.htm. |