Ver Mensaje Individual
  #12 (permalink)  
Antiguo 28/04/2014, 15:48
Avatar de Landa11
Landa11
 
Fecha de Ingreso: febrero-2014
Ubicación: En algún lugar de mi oficina
Mensajes: 148
Antigüedad: 10 años, 3 meses
Puntos: 1
Respuesta: Imagen cargada previamente en un input type

Código PHP:
Ver original
  1. <?php
  2.  
  3. // Conectando, seleccionando la base de datos
  4. $link = mysql_connect('localhost', 'root', '')
  5.     or die('No se pudo conectar: ' . mysql_error());
  6. mysql_select_db('productos', $link) or die('No se pudo seleccionar la base de datos');
  7.  
  8.  
  9. /*$link = mysql_connect('mysql.nixiweb.com','u702856234_regis','lic=bankai11*') or die('No se pudo conectar: '.mysql_error());
  10. mysql_select_db('u702856234_regis', $link) or die('No se puedo conectar con la Base de Datos: '.mysql_error());*/
  11.  
  12.  
  13. if($_POST['cantidad'] == "")
  14. {
  15.     //echo "<br /><center><p><h2>Los campos son necesarios favor de introducirlos. Puedes acceder haciendo <a href='index.html'>CLICK AQUÍ</a></h2></p></center>";
  16. }
  17. else
  18. {
  19. $id_sucursal = strip_tags($_POST['id_sucursal']);
  20. $cantidad = strip_tags($_POST['cantidad']);
  21. $producto = strip_tags($_POST['producto']);
  22. $marca = strip_tags($_POST['marca']);
  23. $modelo = strip_tags($_POST['modelo']);
  24. $observaciones = strip_tags($_POST['observaciones']);
  25. $categoria = strip_tags($_POST['categoria']);
  26.  
  27. if((!empty($_FILES['imagen'])) && ($_FILES['imagen']['error'] == 0))
  28. {
  29.     if($_FILES['imagen']['type'] != 'image/jpeg' && $_FILES['imagen']['type'] != 'image/png')
  30.     {
  31.         echo "<meta http-equiv='REFRESH' content='0 ; url=index.html'>
  32.            <script>
  33.                alert('Error con el archivo seleccionado. Ingrese una imagen válida');
  34.            </script>";
  35.     }
  36.     else
  37.     {
  38.         //Array de archivos disponibles
  39.         $archivos_disp_ar = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff');
  40.         //Carpeta donde se guardan las imagenes
  41.         $ruta="imagenes";
  42.         //recibimos el campo de imagen
  43.         $archivo=$_FILES['imagen']['tmp_name'];
  44.         //guardamos el nombre original de la imagen en un archivo
  45.         $nombreArchivo=$_FILES['imagen']['name'];
  46.  
  47.         $ruta=$ruta."/".$nombreArchivo;
  48.         $id_imagen=rand(1,1000);
  49.         move_uploaded_file($archivo,$ruta."/".$nombreArchivo);
  50.     }
  51. }
  52. else
  53. {
  54.     $ruta = "imagenes/default.jpg";
  55.     $id_imagen=rand(1,1000);
  56. }
  57. $agregar = mysql_query("INSERT INTO lista_productos (id_sucursal, cantidad, producto, marca, modelo, observaciones, categoria, id_imagen, imagen) VALUES ('$id_sucursal', '$cantidad', '$producto', '$marca', '$modelo', '$observaciones', '$categoria', '$id_imagen', '$ruta')");
  58.  
  59.  
  60. if($agregar)
  61. {
  62.     echo 'Los datos fueron registrados correctamente ';
  63.     echo '<br/>ID Sucursal: '.$id_sucursal;
  64.     echo '<br/>Cantidad: '.$cantidad;
  65.     echo '<br/>Producto: '.$producto;
  66.     echo '<br/>Marca: '.$marca;
  67.     echo '<br/>Modelo: '.$modelo;
  68.     echo '<br/>Observaciones: '.$observaciones;
  69.     echo '<br/>Categoria: '.$categoria;
  70.     echo '<br/>ID Imagen: '.$id_imagen;
  71.     echo '<br/>Imagen: '.$ruta;
  72. }
  73. else
  74. {
  75.     echo 'Hubo problemas al registrar los datos: '.@mysql_error();
  76. }
  77.  
  78. //Código para guardar la imagen
  79. if($agregar)
  80. {
  81.     echo "<html>
  82.        <head>
  83.        </head>
  84.        <body>
  85.        <meta charset='utf-8' charset='iso-8859-1' content='' http-equiv='content-type'>
  86.            <meta http-equiv='REFRESH' content='0 ; url=verDatos.php'>
  87.            <script>
  88.                alert('Imagen insertada con exito');
  89.            </script>
  90.        </body>
  91. </html>";
  92. }
  93. else
  94. {
  95.     echo "<html>
  96.        <head>
  97.        </head>
  98.        <body>
  99.            <meta http-equiv='REFRESH' content='0 ; url=verDatos.php'>
  100.            <script>
  101.                alert('La insercion Fallo');
  102.            </script>
  103.        </body>
  104.    </html>";
  105. }
  106. //}
  107. }
  108. ?>
__________________
Ayudando a la gente con nuestros códigos para poder tener el conocimiento adecuado y ser libres!