I've tried several approaches to displaying it, and all different attempts have lead me to this code.
Still only shows me broken image icon.
Here is code to upload image
<form enctype="multipart/form-data" action="loggedin.php" method="post" name="changer">
Photo name: <input type="text" name="photoName"><br>
<textarea name="caption" cols="25" rows="5">
Enter your caption here...
</textarea><br>
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" accept = "image/jpg"accept "image/png" type="file">
<input value="Upload" type="submit">
<?php
//check to see if the user where sending to, exists
if(isset($_FILES['image']) && $_FILES['image']['size'] > 0 && isset($_POST['photoName']))
{
//temporary file name
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
$imageType = $_FILES['image']['type'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
//$data = addslashes($data);
fclose($fp);
// this is where we check to see if the user exists in the database
//create sql string to retrieve the string from the database table "users"
$sql="INSERT INTO photos (photoName, caption, photoData, photoType, userName)
VALUES
('$_POST[photoName]','$_POST[caption]','$tmpName','$imageType', '$currentUser')";
//For debugging purposes
if(!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
else
{
echo "Your Image has been Added";
}
}
here is display image code
if(isset($_POST['usersImage'])){
//code to show images
$user = $_POST['usersImage'];
$sql = "SELECT * FROM `photos` WHERE userName = '$user'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
switch ($row['photoType']) {
case 'image/jpeg':
//echo "<tr>";
//echo '<img src="data:image/jpeg;base64,'. base64_encode($row['photoData'])."\"></td>";
//echo "</tr>";
echo "<br>";
echo '<img src=data:image/jpeg>' .$row['photoData']. '.jpeg'.'</p>';
echo '<p id="caption">'.$row['caption'].' </p>';
break;
}
}
}
The commented out echos are the different attempts I've tried to solving my problem

New Topic/Question
Reply




MultiQuote




|