I know I have been posting quite a few questions lately but I’m stuck on one of those projects that request things that you’ve never done before, I believe though that this is the last piece to solve the puzzle.
I have created a form to upload images to MySQL, I can display them in the browser by specifying the ID like this: [
url...] show.php?id=1 and just when I thought I was getting finished I remember the little fact that I need those images to have a specific height (I can’t ask the end users to resize their images before uploading them) so here is where I am now.
Some research has led me to figure I need to use imagecopyresized, I have been reading about it and I could not mix it or make it work with the script that serves the images in the browser which would be the following:
<?php
$username = "user";
$password = "pass";
$host = "localhost";
$database = "binary";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("");
}
else{
$query = mysql_query("SELECT * FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
}
?>
Or maybe there are better options to resize images from a DB, I don’t need to keep two copies, I just need the one resized to fit a max height, could someone give me a little extra help here? Thank you :)