Ver Mensaje Individual
  #27 (permalink)  
Antiguo 16/11/2015, 05:18
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?

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