Learn how to debug scripts by adding breakpoints and also to find the variable types, etc"
// useful to find which if/endif, while, branch selected
echo '<br> Line ==> ' .__line__ .'<br>' ;
// show any type of variable and add lines
echo '<pre>'; print_r($varableName); echo '</pre>';
// Stop execution
die;
FIRST: Are imageID and imageId the same?
SECOND: I can’t say for sure but I doubt loading a webpage path into a scr line is going return an image.
THIRD: On preview.php, NOTHING can be sent to the browser such as a blank line, i.e.
//preview.php
or the header will fail. I have never used Blob to hold images for web display and even though I did get preview.php to display the uploaded image, nothing is sent to the browser before the header. You have <img being sent to the browser but what is loaded to src is not a path to an image.
OK after some WEB searching you can simply display the image like so.
<?php
$sql = "SELECT imageType,imageData FROM trial ORDER BY imageID DESC LIMIT 1";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result)){
echo '<img height="250px" width="250px" src="data:'.$row['imageType'].';base64,'.base64_encode($row['imageData']).'"/>';
}
?>
I endeavour to always specify image dimensions because it allocates the correct space and prevents the page from jumping to insert the image after it is loaded.
I usually do not show full sized images but upload three image sizes and in most cases I am calling thumb or tile sized images which load pretty fast.
Most pages I create are usually dynamic in width and most image containers would be a part of that width usually based off the screen width. I usually define the image as the child of the image with width:100% and height:auto; A basic example:
Well true that defining the dimension will load the <img at the specified size before the image is rendered, thus no jumping. So you are absolutely correct.
A major annoyance of mine is on a forum site, where I scroll to the end of a thread to see the latest entries and find that I have to keep scrolling down, over and over again, because whoever wrote the forum software doesn’t specify the image size. It’s surprising how many forum software packages don’t do this. I think they all assume we have unlimited bandwidth and speed. Goes back to the thought that developers should have slow hardware and internet access so they can test real-world response times.
In the opening comment you are saving the image with $_SESSION[‘id’] being the value for user_id. So it is assumed you are dealing with login system where there is a $_SESSION[‘id’] for each user. In your trial table, what values are saved thus far during testing? Is it the ID for the user?