By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,727 Members | 757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,727 IT Pros & Developers. It's quick & easy.

Select a Item from a tree

P: 1
Hi everyone,

how can i select an item from a directory and export the full name of it (for example test.txt) to an variable

the code on the dir list that i have is:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $show_path = 1;   # Show local path.
  3. $show_dotdirs = 1;   # Show '.' and '..'.
  4.  
  5. $path = substr($_SERVER['SCRIPT_FILENAME'], 0,
  6.     strrpos($_SERVER['SCRIPT_FILENAME'], '/') + 1);
  7. ?>
  8. <html>
  9.   <head>
  10.     <title>DIR</title>
  11.     <style type="text/css">
  12.       body {
  13.         font-family: Verdana, Arial, sans-serif;
  14.         margin: 40px;
  15.         text-align: center;
  16.       }
  17.  
  18.       body,
  19.       th,
  20.       td {
  21.         background-color: #ffffff;
  22.       }
  23.  
  24.       a:link {
  25.         color: #666666;
  26.         text-decoration: underline;
  27.       }
  28.       a:visited {
  29.         color: #444444;
  30.         text-decoration: underline;
  31.       }
  32.       a:hover {
  33.         color: #666666;
  34.         text-decoration: none;
  35.       }
  36.       a:active {
  37.         color: #660000;
  38.         text-decoration: none;
  39.       }
  40.  
  41.       table {
  42.         background-color: #222222;
  43.         border: #cccccc solid 1px;
  44.         border-spacing: 1px;
  45.         width: 480px;
  46.       }
  47.       th {
  48.         background-color: #4466aa;
  49.         color: #ffffff;
  50.         font-size: 11pt;
  51.         font-weight: bold;
  52.         text-align: left;
  53.         padding: 2px;
  54.       }
  55.       td {
  56.         background-color: #eeeeee;
  57.         color: #666666;
  58.         font-size: 9pt;
  59.         font-weight: normal;
  60.         padding: 6px;
  61.       }
  62.     </style>
  63.   </head>
  64.   <body>
  65.  
  66.     <table cellspacing="1">
  67.       <tr>
  68.         <th><?php if ($show_path == 1) { echo $path; } else { echo 'content of this directory'; } ?></th>
  69.       </tr>
  70.       <tr>
  71.         <td>
  72. <?php
  73. $dirs = array();
  74. $files = array();
  75.  
  76. $dir = dir($path);
  77. while ($entry = $dir->read()) {
  78.     if (($entry != '.') and (substr($entry, -4) != '.php')) {
  79.         if (is_dir($entry)) {
  80.             if (($entry != '..') or $show_dotdirs){
  81.                 $dirs[] = $entry;
  82.             }
  83.         } else {
  84.             $files[] = $entry;
  85.         }
  86.     }
  87. }
  88. $dir->close();
  89.  
  90. sort($dirs);
  91. foreach ($dirs as $dir) {
  92.     printf('<strong>&lt;</strong> <a href="%s">%s</a> <strong>&gt;</strong><br />' . "\n", $dir, $dir);
  93. }
  94.  
  95. sort($files);
  96. foreach ($files as $file) {
  97.     printf('<a href="%s">%s<br />' . "\n", $file, $file);
  98. }
  99. ?>
  100.         </td>
  101.       </tr>
  102.     </table>
  103. <button type="button" onClick="window.location.href='../../main_login.php'";>Retroceder</button>
  104.   </body>
  105. </html>
  106.  
Feb 28 '11 #1
Share this Question
Share on Google+
1 Reply


JKing
Expert 100+
P: 1,206
Have a look at the realpath() function in PHP.
Feb 28 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.