53 / 53 / 4
Регистрация: 26.05.2011
Сообщений: 379
1

Просмотр всех ваших файлов и папок на сервере

29.05.2011, 01:11. Показов 4510. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Очень интересная и полезная штучка.
С ее помощью вы сможете просматривать все ваши файлы и папки на веб сервере...
Показывает размеры всех файлои и число когда было поднято.

Единственное только желателно ее скрыть под вашим логином чтобы никто ее не смог просматривать эту страничку....

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<?PHP
/*
+-----------------------------------------------------------------------------------+
|                                                                                   |
|   dirLIST - PHP Directory Lister Version 0.1                                      |
|   Copyright © 2007 Hamdiya                                                       |
|   Support:hamdiya.dev@gmail.com                                                   |
|                                                                                   |
|   dirLIST is free software; you can redistribute it and/or modify                 |
|   it under the terms of the GNU General Public License as published by            |
|   the Free Software Foundation; either version 2 of the License, or               |
|   (at your option) any later version.                                             |
|                                                                                   |
|   This program is distributed in the hope that it will be useful,                 |
|   but WITHOUT ANY WARRANTY; without even the implied warranty of                  |
|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   |
|   GNU General Public License for more details.                                    |
|                                                                                   |       
|   You should have received a copy of the GNU General Public License               |
|   along with this program; if not, write to the Free Software                     |
|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA       |
|                                                                                   |
+-----------------------------------------------------------------------------------+
*/
//= = = = = = = = = = = = = = = = = = = = = = = = = =
//U  S  E  R    C  O  N  F  I  G  U  R  A  T  I  O  N   
//= = = = = = = = = = = = = = = = = = = = = = = = = =
 
 
//You can start by placing this file in the folder you wish to browse and you should be all set. If you want, you can change a few settings below for further customization. Good luck :)
//
//Directory to browse ***WITH TRAILING SLASH***. Leave it as "./" if you want to browse the directory this file is in.
$dir_to_browse = "./"; //default = "./"
 
//Exclude this file from being listed? 1:Yes 2:No
$exclude_this_file = 1;
 
//Files or folders to exclude from listing - note:index.php is this file by default.
$exclude = array('.','..','.ftpquota','.htaccess');
 
//Files to exclude based on extension (eg: '.jpg' or '.PHP') and weather to be case sensative. 1:Enable 0:Disable
$exclude_ext = array('');
$case_sensative_ext = 1; //default = 1
 
//Enable/Disable statistics/legend/load time. 1:Enable 0:Disable
$statistics = 1; //default = 1
$legend = 1; //default = 1
$load_time = 1; //default = 1
 
//Show folder size? Disabling this will greatly improve performance if there are several hundred folders/files. However, size of folders wont show. 1:Enable 0:Disable
$show_folder_size = 1; //default = 1
 
//Alternating row colors. EG: "#CCCCCC"
$color_1 = "#E8F8FF"; //default = #E8F8FF
$color_2 = "#B9E9FF"; //default = #B9E9FF
$folder_color = "#CCCCCC"; //default = #CCCCCC
 
//Table formatting
$top_row_bg_color = "#006699"; // default = #006699
$top_row_font_color = "#FFFFFF"; //default = #FFFFFF
$width_of_files_column = "450"; //value in pixles. default = 450
$width_of_sizes_column = "100"; //value in pixles. default = 100
$width_of_dates_column = "125"; //value in pixles. default = 100
$cell_spacing = "5"; //value in pixles. default = 5
$cell_padding = "5"; //value in pixles. default = 5
 
 
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//U  S  E  R    C  O  N  F  I  G  U  R  A  T  I  O  N    -    D  O  N  E  
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 
//start load time
if($load_time)
{
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime;
}
//Start load time -done
 
if(get_magic_quotes_gpc())
$folder = stripslashes($_GET['folder']);
else
$folder = $_GET['folder'];
$dir_to_browse_original = $dir_to_browse;
if(!empty($folder))
{
    $dir_to_browse = $dir_to_browse.$folder."/";
    $folder_slash = $folder."/";
}
?>
<!-- Output basic HTML code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?PHP
if($folder == "")
echo "Index of: home/";
else
echo "Index of: ".array_pop(explode("/", $folder))."/"; ?></title>
<style type="text/css">
<!--
body,td,th {
    font-family: Tahoma, Verdana;
    font-size: 10pt;
}
a:link {
    color: #006699;
    text-decoration: none;
}
a:visited {
    text-decoration: none;
    color: #006699;
}
a:hover {
    text-decoration: underline;
    color: #0066CC;
}
a:active {
    text-decoration: none;
    color: #0066CC;
}
.top_row {color: <?PHP echo $top_row_font_color; ?>; font-weight: bold; font-size: 14px; }
.table_border {
    border: 1px dashed #666666;
}
.path_font {font-family: "Courier New", Courier, monospace}
-->
</style>
<body>
<!-- Output basic HTML code -done -->
<?PHP
//Check if directory is valid
$folder_exists = 1;
if(!is_dir($dir_to_browse)) 
{
    $folder = "";
    $folder_exists = 0;
}
 
if($folder_exists == 0)
{
    echo display_error_message("<b>Error:</b> Folder specified does not exist. This could be because you manually entered the folder name in the URL or you don't have permission to access this folder");
    exit;
}
//Chcek if directory is valid -done
 
//This is a VERY important security feature. It wont allow people to browse directories above $dir_to_browse. Edit this part at your own risk
$folders_in_URL_security = explode("../",$folder);
if(count($folders_in_URL_security) > 1)
{
    echo display_error_message("<b>Access Denied.</b>");
    exit;
}
//Seurity feature -done
 
//Create navigation links
$this_file_name_array = explode("/",$_SERVER['PHP_SELF']);
$this_file_name = array_pop($this_file_name_array);
$folders_in_URL = explode("/",rawurldecode($folder));
$depth = count($folders_in_URL);
 
foreach($folders_in_URL as $key => $val)
{
    $_temp = $_temp."/".$val;
    $folders_in_URL_array[$key] = $_temp;
    if($key == 0)
    {
        $_temp = $folders_in_URL[0];
        $folders_in_URL_array[0] = $folders_in_URL[0];
    }
}
 
$nav_links = "<a href=\"$this_file_name\">home</a>/";
 
for($i=0;$i<$depth;$i++)
{
    if(!empty($folder))
    $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>/";
    else
    $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>";
}
 
echo "Index of: ".$nav_links."<br><br>";
//Create navigation links -done
 
//Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays
$dir_content = get_dir_content($dir_to_browse);
 
//If file extensions are NOT case sensative
if($case_sensative_ext == 0)
{
    foreach($exclude_ext as $key => $val)
    {
        $temp_ext = $val;
        $exclude_ext[$key] = strtolower($temp_ext);
    }
}
//If file extensions are NOT case sensative -done
 
//Filter content
$filtered_content = array();
$filter_count = 0;
foreach($dir_content as $key => $val)
{
    $file_ext = explode(".",$val);
    $file_ext = ".".array_pop($file_ext);
    if(!in_array($val, $exclude) && !in_array($file_ext,$exclude_ext))
    {
        $filtered_content[$filter_count] = $val;
        $filter_count++;
    }
}
if($exclude_this_file == 1)
{
    $array_with_this_file_name = array();
    $temp_filtered_content = $filtered_content;
    $filtered_content = array();
    foreach($temp_filtered_content as $key => $val)
    {
        if($val == $this_file_name)
        {
            array_push($array_with_this_file_name, $key);   
        }
        else
        $filtered_content[$key] = $val; 
    }
    foreach($array_with_this_file_name as $key => $val)
    {
        $temp_path = $folder."/".$this_file_name;
        if(substr($temp_path,0,1) == "/") $temp_path = substr($temp_path,1);
        if(is_file($temp_path))
        {
            $md5_temp_path = md5_file($temp_path);
            $md5_this_file = md5_file($_SERVER['SCRIPT_FILENAME']);
            if($md5_temp_path != $md5_this_file)
            {
            array_push($filtered_content, $this_file_name);
            }
        }
        else
        array_push($filtered_content, $this_file_name);
        
    }
}   
//Filter content -done
 
//Get directory content and seperate files and folders into 2 arrays -done
 
if(!empty($filtered_content))
{
    $folders_count = 0;
    $files_count = 0;
    
    $folders_array = array();
    $files_array = array();
        
    foreach($filtered_content as $key => $val)
    {
        $path = $dir_to_browse.$val;
        if(is_dir($path))
        {
            array_push($folders_array, $val);
        }
        else
        {
            array_push($files_array, $val);
        }
    }
    
    //Sort the files and folders arrays
        if(!empty($folders_array)) natcasesort($folders_array);
        if(!empty($files_array)) natcasesort($files_array);
        $folders_array_temp = array();
        $files_array_temp = array();
        foreach($folders_array as $key => $val)
        {
            array_push($folders_array_temp, $val);
        }
        foreach($files_array as $key => $val)
        {
            array_push($files_array_temp, $val);
        }
        $folders_array = $folders_array_temp;
        $files_array = $files_array_temp;
    //Sort the files and folders arrays -done
    
    //Determin OS PHP is running on
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') 
    $OS = "windows";
    //Determin OS PHP is running on -done
    
    //Get files and folders sizes and creation dates
        $folders_cdate_array = array();
        $files_cdate_array = array();
        $folders_size_array = array();
        $files_size_array = array();
        $files_total_size = 0;
        $folders_total_size = 0;
        
        foreach($files_array as $key => $val)
        {
            $path = $dir_to_browse.$val;
            $files_cdate_array[$key] = date("d F Y", filectime($path));
            $file_bytes = filesize($path);
            $files_size_array[$key] = letter_size($file_bytes);
            $files_total_size = $files_total_size + $file_bytes;
        }
        
        foreach($folders_array as $key => $val)
        {
            $path = $dir_to_browse.$val;
            $path_slash = $dir_to_browse.$val."/";
            $folders_cdate_array[$key] = date("d F Y", filectime($path));
            if($show_folder_size)
            {
                if($OS == "windows")
                $folder_bytes = folder_size_windows($path_slash);
                else
                $folder_bytes = folder_size($path);
                $folders_size_array[$key] = letter_size($folder_bytes);
                $folders_total_size = $folders_total_size + $folder_bytes;
            }
            else
            $folders_size_array[$key] = "-";
        }
    //Get files and folders sizes and creation dates -done
    
    //Generate content links to an array
        $folders_links_array = array();
        $files_links_array = array();
        
        foreach($folders_array as $key => $val)
        {
            $folders_links_array[$key] = '<a href="'.$this_file_name.'?folder='.rawurlencode($folder_slash).rawurlencode($val).'">'.$val."</a><br>";
        }
        
        foreach($files_array as $key => $val)
        {
            if(empty($folder))
            $files_links_array[$key] = '<a href="'.$dir_to_browse_original.rawurlencode($val).'">'.$val."</a><br>";
            else
            $files_links_array[$key] = '<a href="'.$dir_to_browse_original.$folder."/".rawurlencode($val).'">'.$val."</a><br>";
        }
    
    //Generate content links to an array -done
    
    //Calculate table dimensions
    $table_width = (6*$cell_padding) + (4*$cell_spacing) + $width_of_files_column + $width_of_sizes_column + $width_of_dates_column;
    //calculate table dimensions -done
    
    //Palce the content into a table
    if($legend) echo "
<table width=\"320\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"table_border\">
  <tr>
    <td width=\"100\" bgcolor=\"#666666\"><font color=\"#FFFFFF\"><strong>KEY</strong></font></td>
    <td width=\"33\">Folder</td>
    <td width=\"24\"><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
      <tr>
        <td colspan=\"4\" bgcolor=\"$folder_color\">&nbsp;</td>
      </tr>
    </table></td>
    <td width=\"17\">File</td>
    <td width=\"24\"><table width=\"24\" height=\"4\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
      <tr>
        <td colspan=\"4\" bgcolor=\"$color_1\">&nbsp;</td>
      </tr>
    </table>     </td>
    <td width=\"5\">|</td>
    <td><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">
      <tr>
        <td colspan=\"4\" bgcolor=\"$color_2\">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table><br>";
    
    if($statistics) 
    {
    echo'
<a href="javascript:;" onMouseDown="if(document.getElementById(\'mydiv\').style.display == \'none\'){ document.getElementById(\'mydiv\').style.display = \'block\'; }else{ document.getElementById(\'mydiv\').style.display = \'none\'; }">Show/hide statistics<br></a>
    <div id="mydiv" style="display:none">
    <table width="320" border="0" cellpadding="5" class="table_border">';
      if($show_folder_size)
      echo'<tr>
        <td width="95" bgcolor="#666666"><font color="#FFFFFF"><strong>Folders count </strong></font></td>
        <td>'.count($folders_array).', consuming: '.letter_size($folders_total_size).'</td>
      </tr>';
      echo'
      <tr>
        <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">Files count </font></strong></td>
        <td>'.count($files_array).', consuming: '.letter_size($files_total_size).'</td>
      </tr>';
      if($show_folder_size)
      echo'<tr>
        <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">Total count </font></strong></td>
        <td>'.(count($folders_array)+count($files_array)).', consuming: '.letter_size(($files_total_size+$folders_total_size)).'</td>
      </tr></table>';}
    echo"
    </table></div><br><table width=\"$table_width\" border=\"0\" cellspacing=\"$cell_spacing\" cellpadding=\"$cell_padding\">
      <tr>
        <td width=\"$width_of_files_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">File</span></td>
        <td width=\"$width_of_sizes_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Size</span></td>
        <td width=\"$width_of_dates_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Date uploaded</span></td>
      </tr>";
     
    
    foreach($folders_links_array as $key => $val)
    {
        echo"<tr>
        <td width=\"$width_of_files_column\" bgcolor=\"$folder_color\">$val</td>
        <td width=\"$width_of_sizes_column\" bgcolor=\"$folder_color\">$folders_size_array[$key]</td>
        <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$folders_cdate_array[$key]</td></tr>";
    }
    foreach($files_links_array as $key => $val)
    {
        if($key%2 == 0) $color = $color_1; else $color = $color_2;
        echo"<tr>
        <td width=\"$width_of_files_column\" bgcolor=\"$color\">$val</td>
        <td width=\"$width_of_sizes_column\" bgcolor=\"$color\">$files_size_array[$key]</td>
        <td width=\"$width_of_dates_column\" bgcolor=\"$color\">$files_cdate_array[$key]</td></tr>";
    }
    echo "</table>";
    //Palce the content into a table -done
    
//Closing curley brace for the if(!empty($filtered_content))
}
//Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays -done
 
//Output if there is no content
if(empty($filtered_content)) 
echo display_error_message("No files or folders in this directory: <span class=\"path_font\"><b>$folder</b></span>");
//Output if there is no content -done
 
//Functions
function get_dir_content($path)
{
    $php_version = substr(phpversion(),0,1);
    if($php_version > 4)
    {
        $content = scandir($path);
        return $content;
    }
    elseif($php_version == 4)
    {
        $content = array();
        if ($handle = opendir($path)) 
        {
            while (false !== ($file = readdir($handle))) 
            {
                array_push($content,$file);
            }
            closedir($handle);
        }
        return $content;
    }
}
 
function folder_size($path)
{
    $folder_size = `du -s $path`;
    $size_array = explode("\t", $folder_size);
    return $size_array[0]*1024;
}
 
function folder_size_windows($path)
{
    $exclude = array('.','..');
    $content = scandir($path);
    
    //Filter content
    $filtered_content = array();
    $filtered_content = array();
    foreach($content as $key => $val)
    {
        if(!in_array($val, $exclude))
        {
            array_push($filtered_content, $val);
        }
    }
    //Filter content -done  
    
    foreach($filtered_content as $key => $val)
    {
        $content_path = $path.$val;
        if(is_dir($content_path))
        {
            
            $content_path = $path.$val."/";
            $directory_size = folder_size_windows($content_path);
            $total_directory_size = $total_directory_size + $directory_size ;
            
        }
        else
        {
            $file_size = filesize($content_path);
            $total_file_size = $total_file_size + $file_size;
        }
    }
    return ($total_file_size + $total_directory_size);
}
 
function letter_size($byte_size)
{
    $file_size = $byte_size/1024;
        if ($file_size >=  1048576)
    {
        $file_size = $file_size/1048576;
        $file_size = sprintf("%01.2f", $file_size);
        $file_size = $file_size." GB";
    }
    elseif ($file_size >=  1024)
    {
        $file_size = $file_size/1024;
        $file_size = sprintf("%01.2f", $file_size);
        $file_size = $file_size." MB";
    }
    else
    {
        $file_size = sprintf("%01.1f", $file_size);
        $file_size = $file_size." KB";  
    }
    return $file_size;
}
 
function display_error_message($message)
{
    return "<table width=\"80%\" cellpadding=\"5\" cellspacing=\"1\" class=\"table_border\">
  <tr>
    <td bgcolor=\"#FFBBBD\">$message</td>
  </tr>
</table>";
}   
//Functions -done
 
//Display load time
if($load_time)
{
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $endtime = $mtime;
    $totaltime = ($endtime - $starttime);
    echo "<br>This page loaded in ".sprintf("%.3f", $totaltime)." seconds";
}
//Display load time -done
?>
<!-- Output basic HTMl code -->
</body>
</html>
<!-- Output basic HTMl code -done -->
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
29.05.2011, 01:11
Ответы с готовыми решениями:

Как получить названия всех файлов и папок находящийся на сервере
Необходимо создать функцию которая возвращает названия файлов и папок находящийся на родительском...

Просмотр всех папок
у меня есть диск, на нём папки: 1 11(подпапка) 12(подпапка) 2 как мне просмотреть папки в...

Рекурсивный просмотр папок и файлов
Почему этот код при нахождении поддиректории в данной папке не хочет заходить рекурсивно в...

Просмотр файлов на сервере, через сайт
Здравствуйте, мне нужно реализовать такую функцию что бы человек который загружает файлы на сервер...

0
29.05.2011, 01:11
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
29.05.2011, 01:11
Помогаю со студенческими работами здесь

Просмотр скрытых файлов и папок с помощью DirListBox and FileListBox
Есть два объекта DirListBox и FileListBox когда с помощью них рассматриваешь своё барахло, то не...

Список файлов/папок у пользователя (НЕ на сервере)
Использую для проекта Webforms, VB.Net, Visual Web Developer Express 2010, .NET 4.0, но это просто...

Названия всех папок и файлов
Как получить список названий всех папок и файлов в определённой папке?

MS Indexing Service, как сделать, что бы индекс собирался не по физической структуре папок и файлов на сервере, а по ссылкам с сайта?
MS Indexing Service Народ, помогите!!! Проблема следующая: нужно делать поиск по сайту, для...

Рекурсивный вывод всех папок и файлов
Господа казалось бы банальный вопрос , но что то я упёрся !!! Вообщем делаю функцию которая...

Вывод всех файлов и папок в консоль
При выполнении программы с аргументом &quot;*.*&quot; ( при любых расскладах , если минимум один файл/фолдер...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru