I am trying to add a picture upload for a project that i am currently doing, but whenever i try this it does not display correctly on the page. But if i add the picture using phpMyadmin it displays fine on the webpage. To display the image on the page i am using this code.
[code=html]<img src=”data:image/jpeg;base64,’. base64_encode( $row[‘review_picture’] ). ‘” style=”height: 150px; width: 150px;” />
For the upload i am working on, it involves a form, with other inputs beside the file upload, but the code below, is in its basic form
[code=html]<form action=”new_review.php” method=”post” name=”myForm”>
<label>Review Picture: </label><input type=”file” name=”review_picture” id=”review_picture”>
</form>
But the part which i am really struggling on is the page, which it is posted to.
[code=php]<?php
Open_Connection();
global $connection_Var;
$data = file_get_contents(‘$_POST[review_picture]’);
$data = base64_encode($data);
mysqli_query($connection_Var,”INSERT INTO review(review_picture) VALUES (‘$base64’) or die (mysql_error());
header( ‘Location: ../index.php’);
Close_Connection();
function Open_Connection()
{
global $connection_Var;
$connection_Var = mysqli_connect(“localhost”,”root”,””,”review_db”);
if (mysqli_connect_errno($connection_Var))
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
}
function Close_Connection()
{
global $connection_Var;
mysqli_close($connection_Var);
}
?>
I have tried many different ways round this, what ever i try i can’t quite get the hang of it, and tbf it the last piece of code is a bit of rough guess. I would be really grateful for any help.