Hello all, I am a PHP newbie and needing some major help working with images in a mysql database using php.
Here is what I am wanting to do!
I have a membership website that I want to create a profile for each member. This profile page will come from a form that the member fills out. Obviously this info goes into a database and then is called later.
I have the form working and it is entering all the data correctly including the images. I am also able to get the data out of the database correctly except for the images!
I am able to get one image to display but then it ignores all the other code!
Here is the code I have:
This is the code I used to upload image into the database: As a blob.
Code: Select all
<?php
if(isset($_POST['upload']) && $_FILES['logo']['size'] > 0)
{
$fileName = $_FILES['logo']['name'];
$tmpName = $_FILES['logo']['tmp_name'];
$fileSize = $_FILES['logo']['size'];
$fileType = $_FILES['logo']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$mysqli = new mysqli("localhost", "XXX", "YYY", "voogahco_microblog");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql ="INSERT INTO logo (cust_id, file_name, file_size, file_type, content, date)
VALUES ('$_SESSION[$cust_id]', '$fileName', '$fileSize', '$fileType', '$content', NOW() )";
$res = mysqli_query($mysqli, $sql);
if ($res === TRUE) {
echo "";
} else {
printf ("Could not insert record: %s\n", mysqli_error($mysqli));
}
}
}
?>
Code: Select all
<?php
$username = "XXX";
$password = "YYY";
$host = "localhost";
$database = "voogahco_test";
@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 = 1;
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM images WHERE image_id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['content'];
header('Content-type: image/jpg');
echo $content;
}
?>
Any help would be greatly appreciated!!
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: