When I try to upload a picture and then put it in the database as a BLOB.
The code that I use works perfectly when inserting into another table, so I basically just used the code of another insert query.
This is the PHP:
<?php
error_reporting(-1);
if (isset($_POST['gallery-upload'])) {
$hostname='**';
$username='**';
$password='**';
$file = $_FILES['image'] ['tmp_name'];
$tmpName = $_FILES['image']['tmp_name'];
$filter = $_POST['filter'];
$fp = fopen($tmpName, 'rb');
try {
$dbh = new PDO("mysql:host=$hostname;dbname=dddoecje_campu",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$stmt = $dbh->prepare("INSERT INTO `gallery`(`id`, `image`, `filter`) VALUES ('',:image,:filter)");
$stmt->bindParam(':filter', $filter);
$stmt->bindParam(':image', $fp, PDO::PARAM_LOB);
$dbh->errorInfo();
$stmt->execute();
// use exec() because no results are returned
header("Location: index.php");
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbh = null;
}
?>
And this is the form:
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-body">
<form action="upload-gallery.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<i class="icon-cloud-upload"></i>
<span>Select file</span>
<input type="file" accept="image/png, image/jpeg, image/gif" data-max-size="5000" name="image">
</div>
<select name="filter">
<option value="all">All</option>
<option value="area">Area</option>
<option value="resort">Resort</option>
<option value="rinjani">Rinjani</option>
</select>
<button style="margin-top: 10px;" name="gallery-upload" class="btn btn-default"><?php echo $upload_gallery;?></button>
</form>
</div>
</div>
</div>
This is what I see in the database after I insert the image:
Everything is inserting fine, but only the BLOB doesn't insert for some reason. Also without the data-max-size
it doesn't work.