Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/01/2006, 12:37
Avatar de gonzalezmfrank
gonzalezmfrank
 
Fecha de Ingreso: julio-2005
Ubicación: Maracaibo - Venezuela
Mensajes: 266
Antigüedad: 18 años, 9 meses
Puntos: 0
De acuerdo

Te sugiero que verifiques "siempre" primero que la imagen exista, no queremos que se le den errores al usuario, aqui un ejemplo de una funcion para ello , a la que puedes pasar un parametro N y chequeas despues el valor desde donde llamas la funcion

Código PHP:
// Funcion para verificar que el archivo existe

function existe_arch($nombre_archivo,$verif,$udir){
    if (
$gestor opendir($udir)) {
       while (
false !== ($archivo readdir($gestor))) { if ( $archivo == $nombre_archivo ) { $verif "S"; } }
          
closedir($gestor);
    }
    return 
$verif;

Para borrarla, está esta funcion ( desde el link de mauled ) que debes optimarla porque no querrias borrar un directorio ?, esta es más compleja que el anterior

Código PHP:
//**
// * rm() -- Vigorously erase files and directories.
// *
// * @param $fileglob mixed If string, must be a file name (foo.txt), glob pattern (*.txt), or directory name.
// *                        If array, must be an array of file names, glob patterns, or directories.
// */
function rm($fileglob)
{
   if (
is_string($fileglob)) {
       if (
is_file($fileglob)) {
           return 
unlink($fileglob);
       } else if (
is_dir($fileglob)) {
           
$ok rm("$fileglob/*");
           if (! 
$ok) {
               return 
false;
           }
           return 
rmdir($fileglob);
       } else {
           
$matching glob($fileglob);
           if (
$matching === false) {
               
trigger_error(sprintf('No files match supplied glob %s'$fileglob), E_USER_WARNING);
               return 
false;
           }     
           
$rcs array_map('rm'$matching);
           if (
in_array(false$rcs)) {
               return 
false;
           }
       }     
   } else if (
is_array($fileglob)) {
       
$rcs array_map('rm'$fileglob);
       if (
in_array(false$rcs)) {
           return 
false;
       }
   } else {
       
trigger_error('Parametro #1 debe ser un nombre de archivo o directorio, o una arreglo de nombres y directorios'E_USER_ERROR);
       return 
false;
   }

   return 
true;


Saludos

Frank