Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/03/2008, 18:42
Avatar de Carlmycol
Carlmycol
 
Fecha de Ingreso: diciembre-2007
Ubicación: Los Teques, Venezuela
Mensajes: 240
Antigüedad: 18 años, 11 meses
Puntos: 3
Problema borrando archivos en Servidor

Bueno ante todo Gracias por ver el Mensaje xP

Y segundo tengo estos dos codigos

Como dije anteriormente quiero borrar archivos del seridor

Buscar.php este es el que enlista los archivos
Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<title>Explorando /<? echo $_GET['ruta']; ?></title> 
</head> 
<body> 
<pre> 
<? 

if (empty($_GET['ruta']) || ereg("^\.", $_GET['ruta'])) { 
    
$dir = './'; 
} 
else { 
    
$dir = $_GET['ruta']; 
} 
if (
is_dir($dir)) { 
     
    function 
tamano($bytes) { 
        
$largo = strlen($bytes); 
        if (
$largo < 4) { 
            
$divisor = 1; 
            
$unidad = 'B'; 
        } 
        else if (
$largo > 3 && $largo < 7) { 
            
$divisor = 1024; 
            
$unidad = 'KB'; 
        } 
        else if (
$largo > 6 && $largo < 10) { 
            
$divisor = pow(1024, 2); 
            
$unidad = 'MB'; 
        } 
        else if (
$largo > 9 && $largo < 12) { 
            
$divisor = pow(1024, 3); 
            
$unidad = 'GB'; 
        } 
        else { 
            
$divisor = pow(1024, 4); 
            
$unidad = 'TB'; 
        } 
        
$salida[0] = round(($bytes / $divisor), 2); 
        
$salida[1] = $unidad; 
        return 
$salida; 
    } 

    
$gd = opendir($dir); 
    if (
$gd) { 
        
$rn = "\r\n"; 
        while ((
$archivo = readdir($gd)) !== false) { 
            if (
ereg("^(.)*\.[a-zA-Z0-9]{1,3}$", $archivo)) { 
                if (
$archivo == 'explorar.php') { break; } 
                
$extension = strtolower(substr($archivo, -3)); 
                
//Para diferente extension diferente icono a mostrar. Añade las que quieras.
                  
switch ($extension) { 
                    case 
'mp3': 
                    case 
'wma': 
                        
$icono = 'snd'; 
                            break;
                    case 
'doc': 
                    case 
'txt': 
                      
$icono = 'word'; 
                            break;
                    case 
'pdf': 
                      
$icono = 'pdf'; 
                            break;
                    case 
'php': 
                    case 
'htm':                     
                        
$icono = 'web'; 
                        break;  
                    case 
'jpg';
                    case 
'gif'; 
                    case 
'tif'; 
                    case 
'png'; 
                        
$icono = 'pic'; 
                        break;                     
                    default: 
                        
$icono = 'unk'; 
                        break; 
                } 
                 
                
$iconos [] = $icono; 
                
$archivos[] = $archivo; 
                
$fechas[] = $fecha; 
                
$tamanos[] = tamano(filesize($dir.$archivo)); 
            } 
            else if (
$archivo != '.' && $archivo != '..') { 
                
$carpetas[] = $archivo; 
            } 
        } 
        
closedir($gd); 
         
        if (
$dir != '.') { 
            
$ruta = explode('/', $_GET['ruta']); 
            
$tot_subdir = count($ruta) - 2; 
            
krsort($ruta); 
            
$volver = '<img src="iconos/bck.png"> <a href="?ruta='; 
            for (
$i = 0; $i < $tot_subdir; $i++) { 
                
$volver .= $ruta[$i].'/'; 
            } 
            
$volver .= '">volver</a>'.$rn; 
             
        } 
         echo 
'<h1><font face="Verdana" color="#FF9933">'.$dir.'</font></h1>';
         if (
$dir != '.') echo $volver;
         
        if (
is_array($carpetas)) { 
            
natcasesort($carpetas); 
            foreach (
$carpetas as $valor) { 
                echo 
'<img src="iconos/fol.png"> <a href="?ruta='.$_GET['ruta'].urlencode($valor).'/">'.$valor.'</a>    '.$rn; 
            } 
        } 
         
        if (
is_array($archivos)) { 
            if (
natcasesort($archivos)) { 
                foreach (
$archivos as $clave => $valor) { 
                    echo 
'<img src="iconos/'.$iconos[$clave].'.png"> <a href="'.$dir.urlencode($valor).'">'.$valor.'</a>    ';
                    
printf("%6.2f ", $tamanos[$clave][0]); 
                    echo 
$tamanos[$clave][1].'   ';
                    echo 
'<a href="./borrar.php?fichero='.$valor.'">Borrar</a>';
                    if (
$dir=='./'){
                    echo 
'<font face="Verdana">Link  <b><u>'.$valor.'</u></b></font>';
                    }
                    else{
                    echo 
'<font face="Verdana">Link  <b><u>'.$dir.$valor.'</u></b></font>'; }
                    echo 
$rn; 
                } 
            } 
        } 
    } 
} 
else { 
    echo 
'El directorio \''.$dir.'\' no es v&aacute;lido.'.$rn;;
                
$volver = '<img src="bck.png"> <a href="?ruta='; 
            for (
$i = 0; $i < $tot_subdir; $i++) { 
                
$volver .= $ruta[$i].'/'; 
            } 
            
$volver .= '">volver</a>'.$rn; 
            echo 
$volver;  
} 
?> 
</pre>
y este el cuel borra el fichero

Borrar.php este es el que borra el fichero especificado
Código PHP:
<!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php
$fichero
=$_GET["fichero"];
//yo tengo el directorio aqui "web1/documentos/" vosotros cambiarlo al vuestro
$path=$_SERVER['DOCUMENT_ROOT']."http://localhost/".$fichero;
unlink($path);
echo 
"<script> alert (\"Archivo borrado con éxito\"); </script>";
?> 
</body>
</html>
Cuando trato de borrar un archivo sale no such file o directory que podra ser?

Última edición por Carlmycol; 11/03/2008 a las 19:03