Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/09/2010, 05:42
Ueki
 
Fecha de Ingreso: septiembre-2009
Mensajes: 210
Antigüedad: 14 años, 7 meses
Puntos: 19
Problema con uploader de archivos.

¡Hola a todos!

Tengo un problema con un uploader de archivos, quizás es con la función copy().
Si pudieran decirme si hay algún fallo...
Es un script modificado por mi.

Saludos.

Código PHP:
Ver original
  1. <?php include('../conectar.php');
  2.  
  3. if($_COOKIE['rol'] != "1" && $_COOKIE['user'])
  4. {?>
  5.  
  6. <?php
  7. $status = "";
  8. if ($_POST["action"] == "upload") {
  9.     // obtenemos los datos del archivo
  10.     $tamano = $_FILES["archivo"]['size'];
  11.     $tipo = $_FILES["archivo"]['type'];
  12.     $archivo = $_FILES["archivo"]['name'];
  13.     $prefijo = substr(md5(uniqid(rand())),0,6);
  14.    
  15.     if ($archivo != "") {
  16.         // guardamos el archivo a la carpeta files
  17.         $destino =  "/subir/files/".$prefijo."_".$archivo;
  18.         if (copy($_FILES['archivo']['name'],$destino)) {
  19.             $status = "Archivo subido: <b>".$archivo."</b>";
  20.             $nombre = $prefijo."_".$archivo;
  21.             $sqlinsertdoc = mysql_query("INSERT INTO docs (nombre)
  22.                                    VALUES ('$nombre')")
  23.                                     or die(mysql_error());
  24.         } else {
  25.             $status = "Error al subir el archivo";
  26.         }
  27.     } else {
  28.         $status = "Error al subir archivo";
  29.     }
  30. }
  31. ?>
  32. <html>
  33. <head>
  34. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  35. <title>PDF Upload</title>
  36. <link href="estilo.css" rel="stylesheet" type="text/css" />
  37. </head>
  38. <body>
  39. <table width="413" border="0" cellspacing="0" cellpadding="0">
  40.   <tr>
  41.     <td width="413" height="40" class="titulo">PDF upload</td>
  42.   </tr>
  43.   <tr>
  44.     <td class="text">Por favor seleccione el archivo a subir:</td>
  45.   </tr>
  46.   <tr>
  47.   <form action="upload.php" method="post" enctype="multipart/form-data">
  48.     <td class="text">
  49.       <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
  50.       <input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
  51.       <input name="action" type="hidden" value="upload" />    </td>
  52.     </form>
  53.   </tr>
  54.   <tr>
  55.     <td class="text" style="color:#990000"><?php echo $status; ?></td>
  56.   </tr>
  57.   <tr>
  58.     <td height="30" class="subtitulo">Listado de Archivos Subidos </td>
  59.   </tr>
  60.   <tr>
  61.     <td class="infsub">
  62.     <?php
  63.     if ($gestor = opendir('files')) {
  64.         echo "<ul>";
  65.         while (false !== ($arch = readdir($gestor))) {
  66.            if ($arch != "." && $arch != "..") {
  67.                echo "<li><a href=\"/subir/files/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
  68.            }
  69.         }
  70.         closedir($gestor);
  71.         echo "</ul>";
  72.     }
  73.     ?>  </td>
  74.   </tr>
  75. </table>
  76. <?php } ?>
  77. </body>
  78. </html>

EDITO:

El error que me marca es el siguiente:
Warning: copy(nombre_del_archivo) [function.copy]: failed to open stream: No such file or directory in /home/ampaciam/domains/ampaciamaria.es/public_html/subir/upload.php on line 18