Ver Mensaje Individual
  #21 (permalink)  
Antiguo 13/11/2015, 06:39
ommmm
 
Fecha de Ingreso: octubre-2015
Ubicación: Barcelona
Mensajes: 66
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Como subir un archivo, dentro de un formulario?

Saludos xfxstudios,

Gracias por la aportación, antes de guardar los archivos en la BBDD com estoy haciendo ahora, prové de hacer-lo de la manera que comentas, pero no conseguí que me descargar el archivo a traves de un <a href... Adjunto a continuación los códigos que utilicé a ver si puedes decir-me el porqué no funciona.

Muchas gracias!!


EmpFrmCreacion.php
Código PHP:
Ver original
  1. <html>
  2.     <head>
  3.         <title></title>
  4.         <META http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">
  5.     </head>
  6.  
  7.     <body bgcolor="#F75353">
  8.     <?php
  9.        
  10.         include '../header.php';
  11.     ?> 
  12.    
  13.     <center>
  14.     <form name="Formulario" id="Formulario" title="Formulario" action="anticempcrear.php" method="post" enctype="multipart/form-data">
  15.         <table align="center" bgcolor="#A9E2F3">
  16.             <tr>
  17.             <tr>
  18.             <tr>
  19.             <tr>
  20.             <tr>
  21.                 <th colspan="3"> <FONT SIZE=6>New RFQ:</font></th>
  22.  
  23.             </tr>
  24.             <tr>
  25.             <tr>
  26.             <tr>
  27.             <tr>
  28.             <tr>
  29.             <tr>
  30.             <tr>
  31.             <tr>
  32.                 <th>IdRFQ</th>
  33.                 <td colspan="3"> <input type="text" name="txtidrfq" size="9" />
  34.                 <th>Data</th>
  35.                 <td colspan="3"> <input type="text" name="txtdata" size="9" />
  36.                 </td>
  37.                 <th>Project Part Number</th>
  38.                 <td colspan="3"> <input type="text" name="txtproject_part_nombre" size="20" />
  39.                 </td>
  40.                 <th>Customer</th>
  41.                 <td colspan="3"> <input type="text" name="txtcustomer" size="25"/></td>
  42.                 <th>Category</th>
  43.                 <td colspan="3"> <input type="text" name="txtcategoria" size="20" />
  44.                 </td>
  45.                
  46.  
  47.  
  48.  
  49.  
  50.             <tr>
  51.             <tr>
  52.              <tr>
  53.             <tr>
  54.             <tr>
  55.             <tr>
  56.              <tr>
  57.             <tr>
  58.             <tr>
  59.             <tr>
  60.             <tr>
  61.             <tr>
  62.             <tr>
  63.             <tr>
  64.             <tr>
  65.             <tr>
  66.                 <th>RM Part Number</th>
  67.                 <td colspan="3"> <input type="text" name="txtRM_part_number" size="23" />
  68.                 </td>
  69.                 <th>Suppliers</th>
  70.                 <td colspan="3"> <input type="text" name="txtsupplier" size="20" />
  71.                 </td>
  72.                 <th>Price</th>
  73.                 <td colspan="3"> <input type="text" name="txtprice" size="20" />
  74.                 </td>
  75.                 <th>Cry2</th>
  76.                 <td colspan="3"> <input type="text" name="txtcry2" size="5" />
  77.                 </td>
  78.                 <th>MOQ</th>
  79.                 <td colspan="3"> <input type="text" name="txtmoq" size="20" />
  80.                 </td>
  81.                
  82.  
  83.  
  84.             <tr>
  85.             <tr>
  86.             <tr>
  87.              <tr>
  88.              <tr>
  89.             <tr>
  90.              <tr>
  91.             <tr>
  92.             <tr>
  93.             <tr>
  94.             <tr>
  95.             <tr>
  96.             <tr>
  97.             <tr>
  98.             <tr>
  99.             <tr>  
  100.                 <th>Volume</th>
  101.                 <td colspan="3"> <input type="text" name="txtvolume" size="23" />
  102.                 </td>  
  103.                 <th>Delivery time</th>
  104.                 <td colspan="3"> <input type="text" name="txtdelivery_time" size="20" />
  105.                 </td>
  106.                 <th>Investment</th>
  107.                 <td colspan="3"> <input type="text" name="txtinvestment" size="25" />
  108.                 </td>
  109.                 <th>Cry</th>
  110.                 <td colspan="3"> <input type="text" name="txtcry" size="5" />
  111.                 </td>
  112.                  <th>Timing</th>
  113.                 <td colspan="3"> <input type="text" name="txttiming" size="20" />
  114.                 </td>
  115.                
  116.  
  117.             <tr>
  118.             <tr>
  119.             <tr>
  120.              <tr>
  121.              <tr>
  122.             <tr>
  123.              <tr>
  124.             <tr>
  125.             <tr>
  126.             <tr>
  127.             <tr>
  128.             <tr>
  129.             <tr>
  130.             <tr>
  131.             <tr>
  132.             <tr>  
  133.                  <th>Responsible</th>
  134.                 <td colspan="3"> <input type="text" name="txtresponisble" size="23" />
  135.                 </td>                
  136.  
  137.                 <th>Incoterms</th>
  138.                 <td colspan="3"> <input type="text" name="txtincoterms" size="25" />
  139.                 </td>
  140.                 <th>Comments</th>
  141.                 <td colspan="3"> <input type="text" name="txtcomments" size="25" />
  142.                 </td>
  143.  
  144.  
  145.  
  146.                 <!-- MAX_FILE_SIZE debe preceder al campo de entrada del fichero -->
  147.     <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
  148.     <!-- El nombre del elemento de entrada determina el nombre en el array $_FILES -->
  149.     Enviar este fichero: <input name="archivo" type="file" />
  150.                  
  151.                
  152.                    
  153.             </tr>
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.            
  162.             <tr>
  163.                 <td align="right"colspan="20" >
  164.                 <input type="submit" value="SEND"/>  
  165.                 </td>  
  166.    
  167.             </tr>
  168.  
  169.  
  170.         </table>
  171.  
  172.    
  173.    
  174.  
  175.  
  176.     </form>    
  177.  
  178.  
  179.     </center>
  180.     <body> 
  181. </html>



EmpCrear.php
Código PHP:
Ver original
  1. <?php
  2.          
  3.         include '../header.php';
  4.     ?>
  5.     <?php
  6.  
  7.  
  8.      
  9.             require_once ('../conexion.inc.php');
  10.             $db1 = @mysql_connect($servidor,$usuario,$password) or die("Error al conectar al DBMS.");
  11.             @mysql_select_db($basedatos) or die("Error al conectar a la BD");
  12.            
  13.  
  14. // En versiones de PHP anteriores a la 4.1.0, debería utilizarse $HTTP_POST_FILES en lugar
  15. // de $_FILES.
  16.  
  17. $dir_subida = '/localweb/subidas/S';
  18. $fichero_subido = $dir_subida . basename($_FILES['archivo']['name']);
  19.  
  20. echo '<pre>';
  21. if (move_uploaded_file($_FILES['archivo']['tmp_name'], $fichero_subido)) {
  22.     echo "El fichero es válido y se subió con éxito.\n";
  23. } else {
  24.     echo "¡Posible ataque de subida de ficheros!\n";
  25. }
  26.  
  27. echo 'Más información de depuración:';
  28. print_r($_FILES);
  29.  
  30. print "</pre>";
  31.  
  32.  
  33. $IdRFQ = $_POST['txtidrfq'];
  34.             $Data = $_POST['txtdata'];
  35.            
  36.             $Suppliers = $_POST['txtsupplier'];            
  37.             $Price = $_POST['txtprice'];  
  38.             $Cry2 = $_POST['txtcry2'];
  39.             $MOQ = $_POST['txtmoq'];
  40.             $Volume = $_POST['txtvolume'];        
  41.             $Investment = $_POST['txtinvestment'];
  42.             $Cry = $_POST['txtcry'];        
  43.             $Timing = $_POST['txttiming'];
  44.              
  45.             $Incoterms = $_POST['txtincoterms'];
  46.             $Comments = $_POST['txtcomments'];
  47.  
  48.            
  49.  
  50.  
  51.  
  52. $q1= "INSERT INTO rfq (idrfq, data, suppliers, price, cry2, moq, volume, investment, timing, cry, incoterms)
  53. values ('$IdRFQ','$Data', '$Suppliers', '$Price', '$Cry2', '$MOQ', '$Volume', '$Investment', '$Timing', '$Cry', '$Incoterms')";
  54.  
  55.    
  56.  
  57. $result = mysql_query($q1)  or die ("No se pudo ejecutar la consulta");
  58.  
  59.  
  60.  
  61.      
  62.    
  63.      
  64.            
  65.             mysql_close();
  66.         ?>