Ver Mensaje Individual
  #5 (permalink)  
Antiguo 20/07/2012, 03:23
kanutocm
 
Fecha de Ingreso: noviembre-2010
Mensajes: 113
Antigüedad: 13 años, 5 meses
Puntos: 10
Respuesta: Como acceder a una carpeta en un host a través de MySQL y PHP

prueba esto, con el siguiente código obtienes un array con las carpetas y archivos de un directorio FTP
Código PHP:
Ver original
  1. <?php
  2. // establecer una conexión básica
  3. $conn_id = ftp_connect($ftp_server);
  4.  
  5. // iniciar sesión con nombre de usuario y contraseña
  6. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  7.  
  8. // obtener la lista de archivos de /
  9. $rawfiles = ftp_rawlist($conn_id, '/');
  10.  
  11. // cerrar la conexión ftp
  12. ftp_close($conn_id);
  13.  
  14. ?>

Luego, una vez tengas el array puedes parsearlo con el siguiente código:
Código PHP:
Ver original
  1. <?php
  2. // here the magic begins!
  3. $structure = array();
  4. $arraypointer = &$structure;
  5. foreach ($rawfiles as $rawfile) {
  6.     if ($rawfile[0] == '/') {
  7.         $paths = array_slice(explode('/', str_replace(':', '', $rawfile)), 1);
  8.         $arraypointer = &$structure;
  9.         foreach ($paths as $path) {
  10.             foreach ($arraypointer as $i => $file) {
  11.                 if ($file['text'] == $path) {
  12.                     $arraypointer = &$arraypointer[ $i ]['children'];
  13.                     break;
  14.                 }
  15.             }
  16.         }
  17.     } elseif(!empty($rawfile)) {
  18.         $info = preg_split("/[\s]+/", $rawfile, 9);      
  19.         $arraypointer[] = array(
  20.             'text'   => $info[8],
  21.             'isDir'  => $info[0]{0} == 'd',
  22.             'size'   => byteconvert($info[4]),
  23.             'chmod'  => chmodnum($info[0]),
  24.             'date'   => strtotime($info[6] . ' ' . $info[5] . ' ' . $info[7]),
  25.             'raw'    => $info
  26.             // the 'children' attribut is automatically added if the folder contains at least one file
  27.         );
  28.     }
  29. }
  30.  
  31. // in $structure is all the data
  32. print_r($structure);
  33.  
  34. // little helper functions
  35. function byteconvert($bytes) {
  36.     $symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  37.     $exp = floor( log($bytes) / log(1024) );
  38.     return sprintf( '%.2f ' . $symbol[ $exp ], ($bytes / pow(1024, floor($exp))) );
  39. }
  40.  
  41. function chmodnum($chmod) {
  42.     $trans = array('-' => '0', 'r' => '4', 'w' => '2', 'x' => '1');
  43.     $chmod = substr(strtr($chmod, $trans), 1);
  44.     $array = str_split($chmod, 3);
  45.     return array_sum(str_split($array[0])) . array_sum(str_split($array[1])) . array_sum(str_split($array[2]));
  46. }
  47.  
  48. ?>

Así, tendrás un array multidimensional ($structure) que contendrá toda la información de cada archivo y carpeta.

Todo el código está sacado de manual oficial de PHP, no es mío
Te dejo el enlace para que le eches un vistazo: http://www.php.net/manual/es/function.ftp-rawlist.php