Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/09/2010, 05:53
Avatar de repara2
repara2
 
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Problema con uploader de archivos.

A ver así:

Código PHP:
<?php include('../conectar.php'); 
 
if(
$_COOKIE['rol'] != "1" && $_COOKIE['user'])
{
?>
 
<?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 =  "/subir/files/".$prefijo."_".$archivo;
        if (
move_uploaded_file($_FILES['archivo']['name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
            
$nombre $prefijo."_".$archivo;
            
$sqlinsertdoc mysql_query("INSERT INTO docs (nombre)
                                    VALUES ('$nombre')"
)
                                    or die(
mysql_error());
        } 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>PDF Upload</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">PDF upload</td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione 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="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 
    
if ($gestor opendir('files')) {
        echo 
"<ul>";
        while (
false !== ($arch readdir($gestor))) {
           if (
$arch != "." && $arch != "..") {
               echo 
"<li><a href=\"/subir/files/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
           }
        }
        
closedir($gestor);
        echo 
"</ul>";
    }
    
?>  </td>
  </tr>
</table>
<?php ?>
</body>
</html>
2 salu2