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->filename, strrpos($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;
}
}
}
?>
gracias!