Foros del Web » Programando para Internet » PHP »

Eliminar Imagen de directorio con PHP

Estas en el tema de Eliminar Imagen de directorio con PHP en el foro de PHP en Foros del Web. Que tal amigos. Estoy tratando de hacer un administrador de imagenes...donde pueda subir y eliminar imagenes.... el subir funciona(script desde http://blog.unijimpe.net ) ṕero quiero agregarle ...
  #1 (permalink)  
Antiguo 03/07/2012, 15:46
 
Fecha de Ingreso: noviembre-2010
Mensajes: 208
Antigüedad: 13 años, 5 meses
Puntos: 3
Eliminar Imagen de directorio con PHP

Que tal amigos.


Estoy tratando de hacer un administrador de imagenes...donde pueda subir y eliminar imagenes....
el subir funciona(script desde http://blog.unijimpe.net) ṕero quiero agregarle la funcionalidad de eliminar y no me resulta...los codigos son los siguientes.


Código PHP:
<?php
require("upload.php");

$status "";
if (
$_POST["action"] == "upload") {
    
$fupload = new Upload();
    
$fupload->setPath("files");
    
$fupload->setFile("archivo");
    
$fupload->isImage(true);
    
$fupload->save();
    
    
$status $fupload->message;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP upload - Imagen</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <table width="413" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="413" height="40" class="titulo">PHP upload </td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione el archivo a subir:</td>
  </tr>
  <tr>
  <form action="index.php" method="post" enctype="multipart/form-data">
    <td class="text">
      <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
      <input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
      <input name="action" type="hidden" value="upload" />      </td>
    </form>
  </tr>
  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
  <tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos </td>
  </tr>
  <tr>
    <td class="infsub">
    <?php 
    $i
=0;
    if (
$gestor opendir('files')) {
        echo 
" <input type='radio' name='delete".$i."' value='/images/".$arch."'>";
               while (
false !== ($arch readdir($gestor))) {
            
               if (
$arch != "." && $arch != "..") {
               echo 
"<a href=\"files/".$arch."\" class=\"linkli\">".$arch."</a>\n";
           }
        if( 
$_POST["delete".$i] == "/images/".$arch ){
            echo 
" NOTA: Se eliminara: ".$_POST["delete".$i];
            
unlink($_POST["delete".$i]);
             }
//fin if
        
}
            echo 
"<br />";
            echo 
"<input type='submit' value='Eliminar' />";
        
closedir($gestor);
        
    }
    
?>
    </td>
    
  </tr>
</table>
</body>
</html>

donde el eliminar esta en imput tipo radio...pero no funciona...

y el upload.php

Código PHP:
<?php 
// file: uploadfile.php
// author: http://blog.unijimpe.net
// date: 27/02/2010
class Upload {
    var 
$maxsize 0;
    var 
$message "";
    var 
$newfile "";
    var 
$newpath "";
    
    var 
$filesize 0;
    var 
$filetype "";
    var 
$filename "";
    var 
$filetemp;
    var 
$fileexte;
    
    var 
$allowed;
    var 
$blocked;
    var 
$isimage;
    
    var 
$isupload;
    
    function 
Upload() {
        
$this->allowed = array("image/bmp","image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");//archivos permitidos
        
$this->blocked = array("php","phtml","php3","php4","js","shtml","pl","py");//archivos NO permitidos
        
$this->message "";
        
$this->isupload false;
    }
    function 
setFile($field) {
        
$this->filesize $_FILES[$field]['size'];//tamano imagen
        
$this->filename $_FILES[$field]['name'];//nombre imagen
        
$this->filetemp $_FILES[$field]['tmp_name'];
        
$this->filetype mime_content_type($this->filetemp);
        
$this->fileexte substr($this->filenamestrrpos($this->filename'.')+1);
        
        
$this->newfile substr(md5(uniqid(rand())),0,8).".".$this->fileexte;
    }
    function 
setPath($value) {
        
$this->newpath $value;
    }
    function 
setMaxSize($value) {
        
$this->maxsize $value;    
    }
    function 
isImage($value) {
        
$this->isimage $value;
    }
    function 
save() {
        if (
is_uploaded_file($this->filetemp)) {
            
// check if file valid
            
if ($this->filename == "") {
                
$this->message "No file upload";
                
$this->isupload false;
                return 
false;
            }
            
// check max size
            
if ($this->maxsize != 0) {
                if (
$this->filesize $this->maxsize*1024) {
                    
$this->message "Large File Size";
                    
$this->isupload false;
                    return 
false;
                }
            }
            
// check if image
            
if ($this->isimage) {
                
// check dimensions
                
if (!getimagesize($this->filetemp)) {
                    
$this->message "Invalid Image File";
                    
$this->isupload false;
                    return 
false;    
                }
                
// check content type
                
if (!in_array($this->filetype$this->allowed)) {
                    
$this->message "Invalid Content Type";
                    
$this->isupload false;
                    return 
false;
                }
            }
            
//comprobar si el archivo esta permitido
            
if (in_array($this->fileexte$this->blocked)) {
                
$this->message "File Not Allowed - ".$this->fileexte;
                
$this->isupload false;
                return 
false;
            }
                    
            if (
move_uploaded_file($this->filetemp$this->newpath."/".$this->newfile)) {
                
$this->message "File succesfully uploaded!";
                
$this->isupload true;
                return 
true;
            } else {
                
$this->message "File was not uploaded please try again";
                
$this->isupload false;
                return 
false;
            }
        } else {
            
$this->message "File was not uploaded please try again";
            
$this->isupload false;
            return 
false;
        }
    }    
}
?>
la imagenes estan en un directorio llamado IMAGES.....con los permisos correspondientes....quiero poder elimnaar imagenes al seleccionar.....orientenme


gracias!
  #2 (permalink)  
Antiguo 03/07/2012, 17:49
Avatar de fjrueda  
Fecha de Ingreso: marzo-2008
Ubicación: Bucaramanga
Mensajes: 313
Antigüedad: 16 años, 1 mes
Puntos: 35
Respuesta: Eliminar Imagen de directorio con PHP

ya intento con la funcion "unlink"
le paso el link de la pagina oficial .... http://php.net/manual/es/function.unlink.php

Etiquetas: directorio, html, imagenes
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:15.