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

Saludos!

Podríais hacer un vistazo a este código, a ver si me sabéis decir que deberia cambiar.

Me sale este error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Archivos de programa\EasyPHP-DevServer-14.1VC9\data\localweb\scripts\premo\EmpCrear.php on line 71

Tipo archivo (MIME formato):
Peso: bytes.


Muchas gracias!


A continuación hay el código del formulario y el que hace la acción:

CODIGO: EmpFrmCreacion.php
Código PHP:
Ver original
  1. <center>
  2. <FORM enctype="multipart/form-data" method="post" action="EmpCrear.php">
  3. Archivo: <INPUT type="file" name="archivo" size="30">
  4.         <table align="center" bgcolor="#A9E2F3">
  5.             <tr>
  6.             <tr>
  7.             <tr>
  8.             <tr>
  9.             <tr>
  10.                 <th colspan="3"> <FONT SIZE=6>New RFQ:</font></th>
  11.  
  12.             </tr>
  13.             <tr>
  14.             <tr>
  15.             <tr>
  16.             <tr>
  17.             <tr>
  18.             <tr>
  19.             <tr>
  20.             <tr>
  21.                 <th>IdRFQ</th>
  22.                 <td colspan="3"> <input type="text" name="txtidrfq" size="9" />
  23.                 <th>Data</th>
  24.                 <td colspan="3"> <input type="text" name="txtdata" size="9" />
  25.                 </td>
  26.                 <th>Project Part Number</th>
  27.                 <td colspan="3"> <input type="text" name="txtproject_part_nombre" size="20" />
  28.                 </td>
  29.                 <th>Customer</th>
  30.                 <td colspan="3"> <input type="text" name="txtcustomer" size="25"/></td>
  31.                 <th>Category</th>
  32.                 <td colspan="3"> <input type="text" name="txtcategoria" size="20" />
  33.                 </td>
  34.                
  35.  
  36.  
  37.  
  38.  
  39.             <tr>
  40.             <tr>
  41.              <tr>
  42.             <tr>
  43.             <tr>
  44.             <tr>
  45.              <tr>
  46.             <tr>
  47.             <tr>
  48.             <tr>
  49.             <tr>
  50.             <tr>
  51.             <tr>
  52.             <tr>
  53.             <tr>
  54.             <tr>
  55.                 <th>RM Part Number</th>
  56.                 <td colspan="3"> <input type="text" name="txtRM_part_number" size="23" />
  57.                 </td>
  58.                 <th>Suppliers</th>
  59.                 <td colspan="3"> <input type="text" name="txtsupplier" size="20" />
  60.                 </td>
  61.                 <th>Price</th>
  62.                 <td colspan="3"> <input type="text" name="txtprice" size="20" />
  63.                 </td>
  64.                 <th>Cry2</th>
  65.                 <td colspan="3"> <input type="text" name="txtcry2" size="5" />
  66.                 </td>
  67.                 <th>MOQ</th>
  68.                 <td colspan="3"> <input type="text" name="txtmoq" size="20" />
  69.                 </td>
  70.                
  71.  
  72.  
  73.             <tr>
  74.             <tr>
  75.             <tr>
  76.              <tr>
  77.              <tr>
  78.             <tr>
  79.              <tr>
  80.             <tr>
  81.             <tr>
  82.             <tr>
  83.             <tr>
  84.             <tr>
  85.             <tr>
  86.             <tr>
  87.             <tr>
  88.             <tr>  
  89.                 <th>Volume</th>
  90.                 <td colspan="3"> <input type="text" name="txtvolume" size="23" />
  91.                 </td>  
  92.                 <th>Delivery time</th>
  93.                 <td colspan="3"> <input type="text" name="txtdelivery_time" size="20" />
  94.                 </td>
  95.                 <th>Investment</th>
  96.                 <td colspan="3"> <input type="text" name="txtinvestment" size="25" />
  97.                 </td>
  98.                 <th>Cry</th>
  99.                 <td colspan="3"> <input type="text" name="txtcry" size="5" />
  100.                 </td>
  101.                  <th>Timing</th>
  102.                 <td colspan="3"> <input type="text" name="txttiming" size="20" />
  103.                 </td>
  104.                
  105.  
  106.             <tr>
  107.             <tr>
  108.             <tr>
  109.              <tr>
  110.              <tr>
  111.             <tr>
  112.              <tr>
  113.             <tr>
  114.             <tr>
  115.             <tr>
  116.             <tr>
  117.             <tr>
  118.             <tr>
  119.             <tr>
  120.             <tr>
  121.             <tr>  
  122.                  <th>Responsible</th>
  123.                 <td colspan="3"> <input type="text" name="txtresponisble" size="23" />
  124.                 </td>                
  125.  
  126.                 <th>Incoterms</th>
  127.                 <td colspan="3"> <input type="text" name="txtincoterms" size="25" />
  128.                 </td>
  129.                 <th>Comments</th>
  130.                 <td colspan="3"> <input type="text" name="txtcomments" size="25" />
  131.                 </td>
  132.  
  133.  
  134.  
  135.          
  136.                  
  137.                
  138.                    
  139.             </tr>
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.            
  150.             <tr>
  151.                 <td align="right"colspan="20" >
  152.                 <INPUT type="submit" name="submit" value="SEND">
  153.                 </td>  
  154.    
  155.             </tr>
  156.  
  157.  
  158.         </table>
  159.  
  160.    
  161.    
  162.  
  163.  
  164.     </form>




CODIGO: EmpCrear.php
Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4.      
  5.             require_once ('../conexion.inc.php');
  6.             $db1 = @mysql_connect($servidor,$usuario,$password) or die("Error al conectar al DBMS.");
  7.             @mysql_select_db($basedatos) or die("Error al conectar a la BD");
  8.            
  9.          
  10.          
  11.            
  12.            
  13.            
  14.             //Primero, arranca el bloque PHP y checkea si el archivo tiene nombre.  Si no fue asi, te remite de nuevo al formulario de inserción:
  15. // No se comprueba aqui si se ha subido correctamente.
  16. if (empty($_FILES['archivo']['name'])){
  17. header("location: EmpFrmCreacion.php?proceso=falta_indicar_fichero"); //o como se llame el formulario ..
  18. }
  19.  
  20.  
  21.  
  22. // archivo temporal (ruta y nombre).
  23. $binario_nombre_temporal=$_FILES['archivo']['tmp_name'];
  24.  
  25. // leer del archvio temporal .. el binario subido.
  26. // "rb" para Windows .. Linux parece q con "r" sobra ...
  27. $archivo_binario = addslashes(fread(fopen($binario_nombre_temporal, "rb"), filesize($binario_nombre_temporal)));
  28.  
  29. // Obtener del array FILES (superglobal) los datos del binario .. nombre, tabamo y tipo.
  30. $archivo_nombre=$_FILES['archivo']['name'];
  31. $archivo_peso=$_FILES['archivo']['size'];
  32. $archivo_tipo=$_FILES['archivo']['type'];
  33.  
  34.  
  35.  
  36.             $IdRFQ = $_POST['txtidrfq'];
  37.             $Data = $_POST['txtdata'];
  38.            
  39.             $Suppliers = $_POST['txtsupplier'];            
  40.             $Price = $_POST['txtprice'];  
  41.             $Cry2 = $_POST['txtcry2'];
  42.             $MOQ = $_POST['txtmoq'];
  43.             $Volume = $_POST['txtvolume'];        
  44.             $Investment = $_POST['txtinvestment'];
  45.             $Cry = $_POST['txtcry'];        
  46.             $Timing = $_POST['txttiming'];
  47.              
  48.             $Incoterms = $_POST['txtincoterms'];
  49.             $Comments = $_POST['txtcomments'];
  50.  
  51.            
  52.  
  53.  
  54.  
  55. $q1= "INSERT INTO rfq (idrfq, data, suppliers, price, cry2, moq, volume, investment, timing, cry, incoterms) archivos (id, archivo_binario, archivo_nombre, archivo_peso, archivo_tipo)
  56. values ('$IdRFQ','$Data', '$Suppliers', '$Price', '$Cry2', '$MOQ', '$Volume', '$Investment', '$Timing', '$Cry', '$Incoterms', '$archivo_binario', '$archivo_nombre', '$archivo_peso', '$archivo_tipo')";
  57. $result = mysql_query($q1);
  58.  
  59.  
  60.   while ($registro=mysql_fetch_assoc($result))
  61.        
  62.         echo "<br> Nombre archivo: ".$registro['archivo_nombre']."";
  63.         echo "<br> Tipo archivo (MIME formato): ".$registro['archivo_tipo']."";
  64.         echo "<br> Peso: ".$registro['archivo_peso']." bytes.<br><br>";
  65.    
  66.  
  67.  
  68.          
  69.            
  70.             mysql_close();
  71.         ?>