Ver Mensaje Individual
  #5 (permalink)  
Antiguo 11/11/2010, 08:11
Avatar de monjeruiz
monjeruiz
 
Fecha de Ingreso: junio-2007
Ubicación: Santiago, Chile
Mensajes: 113
Antigüedad: 16 años, 10 meses
Puntos: 3
Respuesta: subir archivos en php

Estimado,

Prueba esta codigo. Es para subir archivos de el tipo que tu declares

Código HTML:
Ver original
  1. <form action="proceso.php" method="post" name="formulario" id="formulario" enctype="multipart/form-data">
  2.         <input type="hidden" name="id" value="<?= $_GET['id'] ?>">
  3.         <input type="hidden" name="boton" value="">
  4.        
  5.         <table width="100%" border="0">              
  6.           <tr>
  7.             <td class="td2">&nbsp;formulario</td>
  8.             <td><input name="archivo" type="file" id="archivo" size="30" /></td>
  9.           </tr>
  10.           </table>
  11.         </form>


y el el PHP proceso.php


Código PHP:
Ver original
  1. $tipo_formulario = $_FILES["archivo"]['type'];
  2. $archivo_formulario = $_FILES["archivo"]['name'];  
  3.  
  4. if($_FILES['archivo']['size'] != 0)
  5. {
  6.     $size_in = 'KB';
  7.     $size_in_bytes = $_FILES['archivo']['size'];
  8.  
  9.     if($size_in == 'B')
  10.     {
  11.         $size = $size_in_bytes;
  12.         $precision = 0;
  13.     }
  14.     elseif($size_in == 'KB')
  15.     {
  16.         $size = (($size_in_bytes / 1024));
  17.         $precision = 2;
  18.     }
  19.     elseif($size_in == 'MB')
  20.     {
  21.         $size = (($size_in_bytes / 1024) / 1024);
  22.         $precision = 2;
  23.     }
  24.     elseif($size_in == 'GB')
  25.     {
  26.         $size = (($size_in_bytes / 1024) / 1024) / 1024;
  27.         $precision = 2;
  28.     }
  29.     $tamano_formulario = round($size, $precision);
  30. }
  31.  
  32. if ($_POST["boton"] == "Ingresar")
  33. {
  34.     if ($archivo != "")
  35.     {
  36.         $destino =  "file/".$archivo_formulario;
  37.         if (copy($_FILES['archivo']['tmp_name'],$destino))
  38.         {
  39.             $mensaje = "Archivo cargado: ".$archivo_formulario.""; 
  40.             $objNoticia = new Noticia();
  41.             $objNoticia->tamano_formulario = $tamano_formulario;
  42.             $objNoticia->tipo_formulario = $tipo_formulario;
  43.             $objNoticia->archivo_formulario = $archivo_formulario;
  44.             $objNoticia->ruta_formulario = $destino;   
  45.        
  46.             $objNoticia->escribirArchivoBD();          
  47.         }
  48.         else
  49.         {
  50.             $mensaje = "Error al subir el archivo";
  51.         }
  52.     }
  53.     else
  54.     {
  55.         $mensaje = "Error al subir archivo";
  56.     }
  57. ?>
  58. <script language="javascript">
  59.     alert("<?= $mensaje ?>");
  60.     location.href="file.php";
  61. </script>
  62. <?
  63. }
__________________
[B]Ingeniero en Informatica
Jose Monje Ruiz [/b]