Foros del Web » Programando para Internet » PHP »

tengo una duda con upload php

Estas en el tema de tengo una duda con upload php en el foro de PHP en Foros del Web. lo que pasa es que tengo una duda con upload php como le puedo hacer para que, no nada mas guarde al servidor si no ...
  #1 (permalink)  
Antiguo 10/10/2008, 16:26
(Desactivado)
 
Fecha de Ingreso: junio-2008
Mensajes: 287
Antigüedad: 15 años, 10 meses
Puntos: 9
tengo una duda con upload php

lo que pasa es que tengo una duda con upload php

como le puedo hacer para que, no nada mas guarde al servidor si no que tambien tenga la opcion de eliminar es estado en san google y dice que tengo que me ter unlink pero como? y en donde? por favor ayuda ya ccasi termino mi web

www.pinkynet.com.mx/upload/uload.php
y este es el codigo de el upload php de antemano gracias...

Código PHP:
<?php 
$status 
"";
if (
$_POST["action"] == "upload") {
    
// obtenemos los datos del archivo 
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];
    
$prefijo substr(md5(uniqid(rand())),0,6);
    
    if (
$archivo != "") {
        
// guardamos el archivo a la carpeta files
        
$destino =  "files/".$prefijo."_".$archivo;
        if (
copy($_FILES['archivo']['tmp_name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
        } else {
            
$status "Error al subir el archivo";
        }
    } else {
        
$status "Error al subir archivo";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Subir archivos a pinkynet.com.mx</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">Subir archivos </td>
  </tr>
  <tr>
    <td class="text">Por favor selecciona el archivo a subir:</td>
  </tr>
  <tr>
  <form action="upload.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="subir" />
      <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 y Fotos Subidos </td>
  </tr>
  <tr>
    <td class="infsub">
    <?php 
    
if ($gestor opendir('files')) {
        echo 
"<ul>";
        while (
false !== ($arch readdir($gestor))) {
           if (
$arch != "." && $arch != "..") {
               echo 
"<li><a href=\"files/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
           }
        }
        
closedir($gestor);
        echo 
"</ul>";
    }
    
?>    </td>
  </tr>
</table>
</body>
</html>
  #2 (permalink)  
Antiguo 10/10/2008, 16:28
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: tengo una duda con upload php

tendrias que selecionar el archivo a eliminar.....
en el siguiente post te paso un codigo muy completo creado por mi que:
sube archivos
ordena el listado de los archivos
elimina archivos selecionandolos
visualizador de los archivos

entre otros.
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #3 (permalink)  
Antiguo 10/10/2008, 16:39
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: tengo una duda con upload php

ARCHIVO: index.php
Código PHP:
<?php 
$status 
"";
$carpeta="archivos/";
if (isset(
$_POST["enviar"])) {
    
// obtenemos los datos del archivo 
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];//nombre fuente
    
$prefijo substr(md5(uniqid(rand())),0,6);
    
    
$extension explode(".",$archivo);
    
$num count($extension)-1;
    
$nombre=basename($archivo,".".$extension[$num]);//nombre base del archivo
    
$imagen=$nombre."_".$prefijo.".".$extension[$num];//nombre real de la imagen
    
if ($archivo != "") {
        
$ext=strtolower($extension[$num]);
        if(
$ext=='jpg' or $ext=='gif' or $ext=='png'){//depende de que deseas que suban....
            
$destino =  $carpeta.$imagen;//lugar donde se almacenara
            
if (copy($_FILES['archivo']['tmp_name'],$destino)){
                
$status "Archivo subido: <b>".$imagen."</b>";
            } else {
                
$status "Error: No se logro subir el archivo";
            }
        } else {
                
$status "Error: Solo se permiten (*.jpg,*.gif,*.png)";
        }
    } else {
        
$status "Error: Archivo no encontrada para subir al Servidor";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Servidor Rustica</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<script language="javascript">
var XMLRequest;    
var XMLRequest2;    
function getHTTPObject() {
    var xmlhttp;
    if(window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    }else if (window.ActiveXObject){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}

function elimina(ar,txt){
    XMLRequest2=getHTTPObject();
    var url="eliminar.php?ar="+ar;//habre la pagina y elimina el archivo enviado
    XMLRequest2.open("GET",url,true);
    XMLRequest2.send(null);
    self.location = "index.php?";
}
</script>
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="413" height="40" class="titulo">Servidor Rustica</td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione el archivo a subir:</td>
  </tr>
  <tr>
      <td class="text">
    <form action="index.php" method="post" enctype="multipart/form-data" >
        <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
          <input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
    </form>
    </td>
  </tr>
  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
  <tr>
    <td height="30" class="subtitulo">Listado de Archivos</td>
  </tr>
  <tr>
    <td class="infsub"><br />
    <?php
    
if ($gestor opendir($carpeta)) {        
        while (
false !== ($arch readdir($gestor))){
            if (
$arch != "." && $arch != "..") {
                
$extension explode(".",$arch);
                
$num count($extension)-1;
                
$ext=strtolower($extension[$num]);
                if(
$ext=='jpg' or $ext=='gif' or $ext=='png'){ $archivos[]=$arch; }
            }
        }
        
closedir($gestor);
        
// Ordenas tu array:
        
sort($archivos); 
        
// (y mueves el puntero interno del array al principio ..)
        
reset($archivos);
        
        
$i=0;
        echo 
'<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
        foreach (
$archivos as $arch){
            
$im=getimagesize($carpeta.$arch);
            
$an=$im[0]; $al=$im[1];
            (
$i%2==0)?$color="#CCCCCC":$color="#999999";
            echo 
"<tr style='background:$color'><td width='300' align='left'><a href='#' class='linkli' >".$arch."</a></td>";
            echo 
"<td width='40' align='center'><a href='#' onClick='window.open(\""$carpeta.$arch."\",\"Imagen\",\"menubar=0,resizable=0,width=".$an.",height=".$al."\");return false;' class=\"abrir\"><img  src='../imagenes/ver.png' width='20' height='20' title='Ver' alt='Ver' border='0'/></a></td>";
            echo 
"<td width='40' align='center'><a href='index.php' onClick='elimina(\"".$arch."\",\"".$txt."\");' class=\"abrir\"><img src='../imagenes/eliminar.png' width='20' height='20' title='Eliminar' alt='Eliminar' border='0'/></a></td><td width='20'></td></tr>";
            
$i++;
        }
        echo 
"</table>";
    }
    
?>
    </td>
  </tr>
</table>
</body>
</html>
archivo: eliminar.php
Código PHP:
<?php
$ar
=$_REQUEST[ar];
if(isset(
$ar)){
    
unlink("imagenes/".$ar);
}
?>
archivo: estilo.css
Código PHP:
body{
    
overflow:scroll;
    
margin:0px;
    
background:#F3F3F3;
}
.
titulo {
    
font-family"Trebuchet MS"Verdana;
    
font-size18px;
    
font-weightbolder;
    
color#990000;
    
text-decorationnone;
    
border-top-width1px;
    
border-bottom-width2px;
    
border-top-stylesolid;
    
border-bottom-stylesolid;
    
border-top-color#D4D0C8;
    
border-bottom-color#D4D0C8;
    
text-alignleft;
    
padding-left30px;
}
.
casilla {
    
font-family"Trebuchet MS"Verdana;
    
font-size11px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
border1px solid #D4D0C8;
}
.
boton {
    
border1px solid #D4D0C8;
    
font-family"Trebuchet MS"Verdana;
    
font-size10px;
    
font-weightbold;
    
color#990000;
    
text-decorationnone;
    
background-color#D4D0C8;
    
vertical-alignmiddle;
}
.
subtitulo {
    
font-family"Trebuchet MS"Verdana;
    
font-size16px;
    
font-weightbolder;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
}
.
subtitulo:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size16px;
    
font-weightbolder;
    
color#999999;
    
text-decorationunderline;
    
text-aligncenter;
}
.
subtext {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
    
background-color#EFEFEF;
}
.
infsub {

    
font-family"Trebuchet MS"Verdana;
    
text-decorationnone;
    
border-top-width1px;
    
border-top-stylesolid;
    
border-top-color#D4D0C8;
}
.
text {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
    
padding-top10px;
}
.
abrir {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
color#CC0000;
    
text-decorationnone;
    
text-aligncenter;
}
a.abrir:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
color#CC0000;
    
text-decorationunderline;
    
text-aligncenter;
}
.
link{

    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightbold;
    
color#990000;
    
text-decorationnone;
    
text-aligncenter;
}
a.link:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightbold;
    
color#990000;
    
text-decorationunderline;
    
text-aligncenter;
}
li {
    list-
style-typecircle;
    
font-size16px;
    
text-decorationnone;
}
a.linkli {
    
font-familyVerdanaArialHelveticasans-serif;
    
font-size12px;
    
color#333333;
    
text-decorationnone;
    
padding-left30px;
}
a.linkli:hover {
    
font-weightbold;
    
color#000000;
    
text-decorationunderline;


y nada mas.... suerte.
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #4 (permalink)  
Antiguo 10/10/2008, 18:09
(Desactivado)
 
Fecha de Ingreso: junio-2008
Mensajes: 287
Antigüedad: 15 años, 10 meses
Puntos: 9
cuando pongo todo el codigo me sale este error

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\wamp\www\upload\index.php on line 106

y cuando quito esa variable me sale esto

Warning: opendir(archivos/) [function.opendir]: failed to open dir: No error in C:\wamp\www\upload\index.php on line 84


Cita:
Iniciado por masterojitos Ver Mensaje
ARCHIVO: index.php
Código PHP:
<?php 
$status 
"";
$carpeta="archivos/";
if (isset(
$_POST["enviar"])) {
    
// obtenemos los datos del archivo 
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];//nombre fuente
    
$prefijo substr(md5(uniqid(rand())),0,6);
    
    
$extension explode(".",$archivo);
    
$num count($extension)-1;
    
$nombre=basename($archivo,".".$extension[$num]);//nombre base del archivo
    
$imagen=$nombre."_".$prefijo.".".$extension[$num];//nombre real de la imagen
    
if ($archivo != "") {
        
$ext=strtolower($extension[$num]);
        if(
$ext=='jpg' or $ext=='gif' or $ext=='png'){//depende de que deseas que suban....
            
$destino =  $carpeta.$imagen;//lugar donde se almacenara
            
if (copy($_FILES['archivo']['tmp_name'],$destino)){
                
$status "Archivo subido: <b>".$imagen."</b>";
            } else {
                
$status "Error: No se logro subir el archivo";
            }
        } else {
                
$status "Error: Solo se permiten (*.jpg,*.gif,*.png)";
        }
    } else {
        
$status "Error: Archivo no encontrada para subir al Servidor";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Servidor Rustica</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<script language="javascript">
var XMLRequest;    
var XMLRequest2;    
function getHTTPObject() {
    var xmlhttp;
    if(window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    }else if (window.ActiveXObject){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}

function elimina(ar,txt){
    XMLRequest2=getHTTPObject();
    var url="eliminar.php?ar="+ar;//habre la pagina y elimina el archivo enviado
    XMLRequest2.open("GET",url,true);
    XMLRequest2.send(null);
    self.location = "index.php?";
}
</script>
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="413" height="40" class="titulo">Servidor Rustica</td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione el archivo a subir:</td>
  </tr>
  <tr>
      <td class="text">
    <form action="index.php" method="post" enctype="multipart/form-data" >
        <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
          <input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
    </form>
    </td>
  </tr>
  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
  <tr>
    <td height="30" class="subtitulo">Listado de Archivos</td>
  </tr>
  <tr>
    <td class="infsub"><br />
    <?php
    
if ($gestor opendir($carpeta)) {        
        while (
false !== ($arch readdir($gestor))){
            if (
$arch != "." && $arch != "..") {
                
$extension explode(".",$arch);
                
$num count($extension)-1;
                
$ext=strtolower($extension[$num]);
                if(
$ext=='jpg' or $ext=='gif' or $ext=='png'){ $archivos[]=$arch; }
            }
        }
        
closedir($gestor);
        
// Ordenas tu array:
        
sort($archivos); 
        
// (y mueves el puntero interno del array al principio ..)
        
reset($archivos);
        
        
$i=0;
        echo 
'<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
        foreach (
$archivos as $arch){
            
$im=getimagesize($carpeta.$arch);
            
$an=$im[0]; $al=$im[1];
            (
$i%2==0)?$color="#CCCCCC":$color="#999999";
            echo 
"<tr style='background:$color'><td width='300' align='left'><a href='#' class='linkli' >".$arch."</a></td>";
            echo 
"<td width='40' align='center'><a href='#' onClick='window.open(\""$carpeta.$arch."\",\"Imagen\",\"menubar=0,resizable=0,width=".$an.",height=".$al."\");return false;' class=\"abrir\"><img  src='../imagenes/ver.png' width='20' height='20' title='Ver' alt='Ver' border='0'/></a></td>";
            echo 
"<td width='40' align='center'><a href='index.php' onClick='elimina(\"".$arch."\",\"".$txt."\");' class=\"abrir\"><img src='../imagenes/eliminar.png' width='20' height='20' title='Eliminar' alt='Eliminar' border='0'/></a></td><td width='20'></td></tr>";
            
$i++;
        }
        echo 
"</table>";
    }
    
?>
    </td>
  </tr>
</table>
</body>
</html>
archivo: eliminar.php
Código PHP:
<?php
$ar
=$_REQUEST[ar];
if(isset(
$ar)){
    
unlink("imagenes/".$ar);
}
?>
archivo: estilo.css
Código PHP:
body{
    
overflow:scroll;
    
margin:0px;
    
background:#F3F3F3;
}
.
titulo {
    
font-family"Trebuchet MS"Verdana;
    
font-size18px;
    
font-weightbolder;
    
color#990000;
    
text-decorationnone;
    
border-top-width1px;
    
border-bottom-width2px;
    
border-top-stylesolid;
    
border-bottom-stylesolid;
    
border-top-color#D4D0C8;
    
border-bottom-color#D4D0C8;
    
text-alignleft;
    
padding-left30px;
}
.
casilla {
    
font-family"Trebuchet MS"Verdana;
    
font-size11px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
border1px solid #D4D0C8;
}
.
boton {
    
border1px solid #D4D0C8;
    
font-family"Trebuchet MS"Verdana;
    
font-size10px;
    
font-weightbold;
    
color#990000;
    
text-decorationnone;
    
background-color#D4D0C8;
    
vertical-alignmiddle;
}
.
subtitulo {
    
font-family"Trebuchet MS"Verdana;
    
font-size16px;
    
font-weightbolder;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
}
.
subtitulo:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size16px;
    
font-weightbolder;
    
color#999999;
    
text-decorationunderline;
    
text-aligncenter;
}
.
subtext {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
    
background-color#EFEFEF;
}
.
infsub {

    
font-family"Trebuchet MS"Verdana;
    
text-decorationnone;
    
border-top-width1px;
    
border-top-stylesolid;
    
border-top-color#D4D0C8;
}
.
text {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightnormal;
    
color#999999;
    
text-decorationnone;
    
text-alignleft;
    
padding-left30px;
    
padding-top10px;
}
.
abrir {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
color#CC0000;
    
text-decorationnone;
    
text-aligncenter;
}
a.abrir:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
color#CC0000;
    
text-decorationunderline;
    
text-aligncenter;
}
.
link{

    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightbold;
    
color#990000;
    
text-decorationnone;
    
text-aligncenter;
}
a.link:hover {
    
font-family"Trebuchet MS"Verdana;
    
font-size12px;
    
font-weightbold;
    
color#990000;
    
text-decorationunderline;
    
text-aligncenter;
}
li {
    list-
style-typecircle;
    
font-size16px;
    
text-decorationnone;
}
a.linkli {
    
font-familyVerdanaArialHelveticasans-serif;
    
font-size12px;
    
color#333333;
    
text-decorationnone;
    
padding-left30px;
}
a.linkli:hover {
    
font-weightbold;
    
color#000000;
    
text-decorationunderline;


y nada mas.... suerte.
  #5 (permalink)  
Antiguo 13/10/2008, 08:07
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: tengo una duda con upload php

amigo no crees que deberias cambiar la carpeta de origen dse tus archivos.....
mis datos son solos mios ps, los puse de ejemplo.....plop.

ademas cuanta con ajax y es rapido, eficaz y muy efectivo. suerte.
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
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 03:31.