
11/04/2008, 06:19
|
| | Fecha de Ingreso: abril-2008 Ubicación: Madrid
Mensajes: 22
Antigüedad: 16 años, 11 meses Puntos: 1 | |
Re: Problemas con borrado de ftp via php sobre windows, Socorroooo!!! YUJUUUU!!!!
Bueno señores tras 48 horas de investigación lo conseguí...
Al parecer la funcion ftp_nlist funciona de forma diferente en windows que en linux así que lo he realizado con la funcion ftp_rawlist pero filtrando el resultado. De esta manera optenemos la misma funcionalidad que ftp_nlist, adjunto el código: Cita: function deleteDirFtp($dir,$configuracion){
if(substr($dir, strlen($dir)-1, 1) != '/')$dir .= '/';
$conn_id = ftp_connect($configuracion->getServidorFtp());
if(ftp_login($conn_id,base64_decode($configuracion->getUserFtp()),base64_decode($configuracion->getPassFtp()))){
ftp_pasv($conn_id, $configuracion->getPasivoFtp());
DeleteDirRecursive($conn_id, $dir);
}
return true;
}
function DeleteDirRecursive($resource, $path) {
$result_message = "";
$list = listaDirectorio($resource, $path);
if(empty($list)){
$list = RawlistToNlist( ftp_rawlist($resource, $path), $path . ( substr($path, strlen($path) - 1, 1) == "/" ? "" : "/" ) );
}
if($list[0]!=$path){
$path.=(substr($path,strlen($path)-1,1)=="/"?"":"/");
foreach($list as $item) {
if ($item != $path.".." && $item != $path.".") {
$result_message .= DeleteDirRecursive($resource, $item);
}
}
if (ftp_rmdir ($resource, $path)) {
$result_message .= "Successfully deleted $path <br />\n";
} else {
$result_message .= "There was a problem while deleting $path <br />\n";
}
}
else {
if (ftp_delete ($resource, $path)) {
$result_message .= "Successfully deleted $path <br />\n";
} else {
$result_message .= "There was a problem while deleting $path <br />\n";
}
}
return $result_message;
}
function RawlistToNlist($rawlist, $path) {
$array = array();
foreach ($rawlist as $item) {
$filename = trim(substr($item, 55, strlen($item) - 55));
if ($filename != "." || $filename != "..") {
$array[] = $path . $filename;
}
}
return $array;
}
function listaDirectorio($conn_id, $dir){
$listado = array();
$list = ftp_rawlist($conn_id, $dir);
for($i=0; $i<count($list);$i++){
for($j=0;$j<strlen($list[$i]);$j++){
if(substr($list[$i],$j,1)==" " && $j-1 > 0 && substr($list[$i],$j-1,1)==" "){
$list[$i] = substr_replace($list[$i],"",$j,1);
$j--;
}
}
$list[$i] = str_replace(" ",";",$list[$i]);
$valores = split(";",$list[$i]);
if (count($valores) >8 && $valores[8]!="" && $valores[8]!="." && $valores[8]!=".."){
if(ftp_chdir($conn_id,$dir)){
$dir.=(substr($dir,strlen($dir)-1,1)=="/"?"":"/");
array_push($listado, $dir.$valores[8]);
}else{
array_push($listado, $valores[8]);
}
}
}
return $listado;
} Está sin depurar pero funciona en todas partes
Ala, hasta otra!!!
http://www.syscover.com |