dimanche 19 avril 2015

uploading images to mysql database using php and bootstrapformvalidation


<?php

session_start();
if(isset($_SESSION['user']))
{

?>

<head>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="vali/css/bootstrapValidator.css"/>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootswatch.js"></script>
<script type="text/javascript" src="vali/js/bootstrapValidator.js"> </script>
<script src="../SnapClient/gui.js"></script>
<script src="../SnapClient/cloud.js"></script>
<script src="../SnapClient/index.html"></script>
</head>
<body>
<br><br><br><br>
<!-- Fixed navbar -->
<?php include("header.html");?>
<div class="container">

<div class="panel panel-default">
<div class="panel-heading">
<h4> <img alt="" height="50" width="80"/> Account Settings </h4>
</div>
<div class="panel-body">


<div class="col-ms-8"><hr><center><h5>Pick Your Profile Picture</h5></center>
<div class="well">
<form class="form-horizontal" id="fileForm" method="post" action="registrationupdate3.php" enctype="multipart/form-data" >

<fieldset>

<div class="form-group">
<label for="image" class="col-lg-3 control-label">Profile Picture<span style="color:red;">*</label>
<div class="col-lg-6">
<input type="file" class="form-control" name="image" />
</div>

</div>

<div class="form-group">
<div class="col-lg-10 col-lg-offset-3">
<button class="btn btn-primary" id="imageupload" name="imageupload" >Update</button>
</div>

</fieldset>
</form>
</div>
</div>

</div>
</div>
</div>
</div>

<script type="text/javascript">

$(document).ready(function() {

$('#fileForm')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},


fields: {
image: {
validators: {
file: {
extension: 'jpeg,png',
type: 'image/jpeg,image/png',
maxSize: 100 * 100,
message: 'The selected file is not valid'
}
}
}
}

})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();

// Get the form instance
var $form = $(e.target);


// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');

// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), function(result) {

if(result=="success")
{
alert(result);

}
else
{
alert(result);

}

}, 'json');


});



});

</script>


<?php include("footer.html");?>
</body>
</html>

<?php
} else {
header("Location:index.html");
}
?>

php file

<?php

session_start();
include 'db_connection.php';

if(is_uploaded_file($_FILES['image']['tmp_name'])) {

$prfimage= addslashes(file_get_contents($_FILES['userImage'] ['tmp_name']));
$username = $_SESSION['user'];

$query= mysql_query("UPDATE userdetails set profileimage='{$prfimage}' WHERE username='".$username."'");

echo $query;

}
else
{
echo "the image file is empty";
}

?>


Always it is showing empty(selected image file is empty). anyone knows why? please help me if anyone knows it. i need to store the user selectd image file in mysql. and i used bootstrapvalidator for validating the image input. i checked without bootstrapvalidator the image is stored in mysql and everything is working fine but if i use bootstrapvalidator it is showing undefined index


Aucun commentaire:

Enregistrer un commentaire