Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/05/2015, 13:35
75aloper
 
Fecha de Ingreso: mayo-2015
Mensajes: 4
Antigüedad: 9 años
Puntos: 0
no me guarda las imagenes el mysql

<!DOCTYPE html>
<html lang="es">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>InsertarRef1</title>



<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>



<!-- Bootstrap Core CSS -->
<!-- <link href="../css/bootstrap.min.css" rel="stylesheet">-->

<!-- Custom CSS -->
<link href="../css/scrolling-nav.css" rel="stylesheet">
<!--Custom my own css-->
<link href="../css/my.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</head>




<body>




<div class="container">

<div class="row">




<?php
$code = $_POST['ean'];
$nombre = $_POST['nombre'];
$id = $_POST['id'];
$descripcion = $_POST['descripcion'];
$imagen = $_POST['fileToUpload'];



$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "codigobarras";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

?>




<?php



$sql = "INSERT INTO productos(id,nombreproducto,ean,descripcion,imagen es)
VALUES ('$id','$nombre','$code','$descripcion','$imagen') ";


if ($conn->query($sql) === TRUE) {


?>

<div class='container'>

<div class='alert alert-info col-lg-4 centrado1 col-sm-12 pull-right'>
<h3 class='text-center' > Su referencia ha sido guardada con éstos datos: </h3>

<p>Nombre:<?php echo $nombre ?></p>
<p> Id: <?php echo $id ?></p>
<p> El EAN: <?php echo $code ?>,</p>
<p>Descripción: <?php echo $descripcion ?> </p>
<p>Foto:<?php echo $imagen ?></p>


</div>


<?php
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>




<div class="col-lg-8 col-sm-12 pull-left" >

<form role="form" id ="myForm" action="insertarRef1.php" method="post" enctype= "multipart/form-data" >


<div class="form-group centrado1">
<input name="nombre" class="form-control input-lg" type="text"
placeholder="Introduzca el nombre del producto" >
</div>


<div class="form-group centrado1">
<input name="ean" class="form-control input-lg" type="text"
placeholder="Introduzca el Ean(Código de barras)" >
</div>



<div class="form-group centrado1">
<input name="descripcion" class="form-control input-lg" type="text"
placeholder="Introduzca la descripcion del producto" >
</div>


<div class="form-group centrado1">
<input name="id" class="form-control input-lg" type="text"
placeholder="Introduzca el id del producto" >
</div>

<div class="form-group centrado1">
<!--<form action="upload.php" method="post" enctype="multipart/form-data">-->

<p class='text-right'>Seleccione imagen:</p>
<input type="file" name="fileToUpload" id="fileToUpload" class="btn btn-primary pull-right"><br><br>
<input type="submit" value="Upload Image" name="submit" class="btn btn-primary pull-right">
<?php
$foto=basename( $_FILES["fileToUpload"]["name"]);
$colocarFoto = "<div id='iz'class='clearfix'> <img src='uploads/$foto'></div>";
echo $colocarFoto;

?>
</form>







<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);


// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<div class='clearfix'>El archivo es una imagen " . $check["mime"] . ".</div>";
$uploadOk = 1;
} else {
echo "El archivo no es una imagen.";
$uploadOk = 0;
}
}



// Check if file already exists
if (file_exists($target_file)) {
echo "<div class='clearfix'>Lo sentimos,el archivo ya existe.</div>";
$uploadOk = 0;
}


// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "<div class='clearfix'>Lo sentimos,el archivo es demasiado grande.</div>";
$uploadOk = 0;
}


// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<div class='clearfix'>Lo sentimos, sólo los archivos :JPG, JPEG, PNG & GIF están permitidos.</div>";
$uploadOk = 0;
}




// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<div class='clearfix'>Lo sentimos, tu fichero no ha sido actualizado.</div>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo " <div class='clearfix'>El archivo ". basename( $_FILES["fileToUpload"]["name"]). " ha sido actualizado.</div>";
} else {
echo "<div class='clearfix'>Lo sentimos, ha habido un error al subir su archivo.</div>";
}
}


?>


</div>

<button type="submit" id="enviar" class="btn btn-primary">Enviar</button>

</form>

</div>

<div class="col-lg-2 col-sm-12 col-lg-offset-5 centrado">

<a href="index1.php"> <button type="button" class="btn btn-default espacio " >
Volver</button>

</div>


</div>
</div>

</body>
</html>