| 1 | <?php |
|---|
| 2 | listar_directorios_ruta("./"); |
|---|
| 3 | function listar_directorios_ruta($ruta){ |
|---|
| 4 | // abrir un directorio y listarlo recursivo |
|---|
| 5 | if (is_dir($ruta)) { |
|---|
| 6 | if ($dh = opendir($ruta)) { |
|---|
| 7 | while (($file = readdir($dh)) !== false) { |
|---|
| 8 | if($file !=".svn" && $file!="." && $file!=".."){ |
|---|
| 9 | //esta línea la utilizaríamos si queremos listar todo lo que hay en el directorio |
|---|
| 10 | //mostraría tanto archivos como directorios |
|---|
| 11 | //echo "<br>Nombre de archivo: $file : Es un: " . filetype($ruta . $file); |
|---|
| 12 | if (is_dir($ruta . $file) && $file!="." && $file!=".."){ |
|---|
| 13 | //solo si el archivo es un directorio, distinto que "." y ".." |
|---|
| 14 | echo "<br>Directorio: $ruta$file"; |
|---|
| 15 | listar_directorios_ruta($ruta . $file . "/"); |
|---|
| 16 | } |
|---|
| 17 | else{ |
|---|
| 18 | //echo "<br>Archivp:$file"; |
|---|
| 19 | //if($file=="aulas.php") |
|---|
| 20 | procesaarchivo($ruta,$file); |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | } |
|---|
| 24 | closedir($dh); |
|---|
| 25 | } |
|---|
| 26 | }else |
|---|
| 27 | echo "<br>No es ruta valida"; |
|---|
| 28 | } |
|---|
| 29 | function procesaarchivo($ruta,$file){ |
|---|
| 30 | $meta='<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'; |
|---|
| 31 | $archivo=realpath($ruta.$file); |
|---|
| 32 | echo "<br>Procesando Archivo:".$file; |
|---|
| 33 | |
|---|
| 34 | $tam=filesize($archivo); |
|---|
| 35 | $fp = fopen($archivo, "rb"); |
|---|
| 36 | $buffer = fread($fp, $tam); |
|---|
| 37 | fclose($fp); |
|---|
| 38 | |
|---|
| 39 | $pos = strpos($buffer,'<HEAD> |
|---|
| 40 | <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'); |
|---|
| 41 | if($pos==0) |
|---|
| 42 | $pos = strpos($buffer,'<head>'); |
|---|
| 43 | if($pos==0) |
|---|
| 44 | return; |
|---|
| 45 | |
|---|
| 46 | $dpl=strlen('<HEAD>'); |
|---|
| 47 | $prebuffer=substr($buffer,0,$pos+$dpl); |
|---|
| 48 | $posbuffer=substr($buffer,$pos+$dpl); |
|---|
| 49 | |
|---|
| 50 | $buffer=$prebuffer."\n\t".$meta.$posbuffer; |
|---|
| 51 | |
|---|
| 52 | /* |
|---|
| 53 | $buffer=ereg_replace( "<"," ",$buffer); |
|---|
| 54 | $buffer=ereg_replace( ">"," ",$buffer); |
|---|
| 55 | $buffer=ereg_replace( "[\n\r]","<BR>",$buffer); |
|---|
| 56 | echo $buffer; |
|---|
| 57 | */ |
|---|
| 58 | |
|---|
| 59 | $fp = fopen($archivo,"w"); |
|---|
| 60 | fwrite($fp, $buffer,strlen($buffer)); |
|---|
| 61 | fclose($fp); |
|---|
| 62 | } |
|---|
| 63 | ?> |
|---|