Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Znaleźć plik w katalogu
Forum PHP.pl > Forum > Przedszkole
rafkam
Hey
Tak jak w temacie - jak znależć konkretny plik(lub pliki) w katalogu i wyswietlic jego (ich)wielkosc, date modyfikacji itp
Guest
jak znależć konkretny plik(lub pliki)
"znaleźć" - sprecyzuj

wyswietlic jego (ich)wielkosc, date modyfikacji itp
:arrow: search
theoden
To sie powinno przydać.dir_functions

  1. <?php
  2. //wyswietlanie zawartosci katalogu wraz z zawartością podkatalogów jeżeli są
  3. $default = &#092;"c:/apache/\";
  4. function show_catalog($dir) {
  5.    echo &#092;"Przeglądanie $dir....<BR>\";
  6.    chdir($dir);
  7.    if(!($handle = opendir($dir))) die(&#092;"Nie mogę otworzyć $dir.\");
  8.  
  9.    while($file = readdir($handle)) {
  10.       if(is_dir($file)) {
  11.          if($file != '.' && $file != '..') {
  12.             echo &#092;"/$file<BR>\";
  13.             show_catalog(&#092;"$dir/$file\");
  14.             chdir($dir);
  15.          }
  16.       }
  17.       else echo &#092;"$file<BR>\";
  18.       
  19.    }
  20.    
  21.    closedir($handle);
  22. }
  23.  
  24. show_catalog($default);
  25.  
  26. ?>

Możesz użyć też scandir" title="Zobacz w manualu PHP" target="_manual

Jeśli chodzi o dane dotyczące plików: wielkość itd. to poszukaj filesize" title="Zobacz w manualu PHP" target="_manual itd. wszystko jest na dodatek z przykładami.
rafkam
Znalazlem cos takiego i dziala. Jeszcze tylko jedna sprawa - jak wyciagnac date takiego sprawdzanego pliku

  1. <?php
  2.  
  3. echo &#092;"<table align=\"center\\">
  4.            <tr><td><br><b>http://10.<font style=\"color: red\">\";
  5. echo  $_GET['ile'];
  6. echo &#092;"</font>.0.25/dbindex.cpt</b><br></td></tr>
  7.             </table>&#092;";
  8.  
  9. echo &#092;"<table width=\"100%\\" border=1><tr><td>\";
  10.  
  11. function remote_file_exists($url)
  12. {
  13.    $head = '';
  14.    $url_p = parse_url ($url);
  15.  
  16.    if (isset ($url_p['host']))
  17.    { $host = $url_p['host']; }
  18.    else
  19.    {
  20.        return '1 Invalid URL host';
  21.    }
  22.  
  23.    if (isset ($url_p['path']))
  24.    { $path = $url_p['path']; }
  25.    else
  26.    { $path = ''; }
  27.  
  28.    $fp = fsockopen ($host, 81, $errno, $errstr, 20);
  29.    if (!$fp)
  30.    { 
  31.        return '2 Unable to connect to remote host';
  32.    }
  33.    else
  34.    {
  35.        $parse = parse_url($url);
  36.        $host = $parse['host'];
  37.  
  38.        fputs($fp, 'HEAD '.$url.&#092;" HTTP/1.1rn\");
  39.        fputs($fp, 'HOST: '.$host.&#092;"rn\");
  40.        fputs($fp, &#092;"Connection: closernrn\");
  41.        $headers = '';
  42.        while (!feof ($fp))
  43.        { $headers .= fgets ($fp, 128); }
  44.    }
  45.    fclose ($fp);
  46.    
  47.    // for debug
  48.    //echo nl2br($headers);
  49.    
  50.    $arr_headers = explode(&#092;"n\", $headers);
  51.    if (isset ($arr_headers[0]))    {
  52.        if(strpos ($arr_headers[0], '200') !== false)
  53.        { return true; }
  54.        if( (strpos ($arr_headers[0], '404') !== false) ||
  55.            (strpos ($arr_headers[0], '410') !== false))
  56.        { return false; }
  57.        if( (strpos ($arr_headers[0], '301') !== false) ||
  58.            (strpos ($arr_headers[0], '302') !== false))
  59.        {
  60.            preg_match(&#092;"/Location:s*(.+)r/i\", $headers, $matches);
  61.            if(!isset($matches[1]))
  62.                return false;
  63.            $nextloc = $matches[1];
  64.            return remote_file_exists($nextloc);
  65.        }
  66.    }
  67.    preg_match('/HTTP.*(ddd.*)r/i', $headers, $matches);
  68.    return '3 Status Code not supported'.
  69.        (isset($matches[1])?&#092;": $matches[1]\":'');
  70. }
  71.  
  72. // sample code
  73.  
  74. $urls = Array();
  75.  
  76.  
  77. $urls[] = &#092;"http://10.1.0.25/dbindex.cpt\";
  78. $urls[] = &#092;"http://10.2.0.25/dbindex.cpt\";
  79.  
  80.  
  81. foreach($urls as $url) {
  82.    echo &#092;"<table width=\"100%\\" border=1 style=\"font-size:11px; font-family: verdana; border-collapse: collapse;border: 0px solid red;\"><tr><td width=\"250\"></b><b>$url</b> - </td>\";
  83.    $ret = remote_file_exists($url);
  84.    $filename = '$url';
  85.    if ($ret===true)
  86.    { 
  87.    
  88.  
  89.  
  90.   //$filemod = filemtime($urls);
  91. //$filemodtime = date(\"d m y\", $filemod);
  92.     //$tTime=$urls[0];
  93.         //$tTime=date(\"d m y\", $tTime);
  94.  // echo \" $tTime<BR>\";
  95.     //echo \"<td>\". $filemodtime.\"</td>\";
  96.     
  97.    echo $filename . ': ' . filesize($filename) . ' bytes';
  98.    echo &#092;"<td>plik istnieje!</td>\"; }
  99.    elseif ($ret===false)
  100.    { echo &#092;"<td><font color=\"#FF0000\">plik nie istnieje!</font></td>\"; }
  101.    else
  102.    {
  103.        echo &#092;"<td>error code: \".$ret.\"</td><td></td></tr></table>\"; 
  104.        
  105.  
  106.    }
  107.   print &#092;"<br>\";
  108.    
  109. } 
  110.  
  111.  
  112. echo &#092;"</td></tr></table>\"; 
  113. ?>


Please helpnijcie cosik!!!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.