Jump to content

Recommended Posts

Hello I am new to this forum and would greatly appreciate any help. I am trying to display a BLOB from my database onto a webpage, but I have no clue how to do this. My current code displays the name of the BLOB, not the BLOB itself. Here is the code:

 

<html>

 

<?php

$con = mysql_connect("mysql17.000webhost.com","a2870045_r ayman3","hawaii" );

 

mysql_select_db("a2870045_picture", $con);

 

$result = mysql_query("SELECT * FROM Art ORDER BY RAND() LIMIT 1");

 

$row= mysql_fetch_array($result);

 

$file = $row["File"];

mysql_close($con);

?>

<center><?=$file?></center>

</html>

 

Again, any help would be appreciated. If you need clarification, please let me know.

Link to comment
https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/
Share on other sites

1. please don't display your mysql information on here...this is sensitive data..

2. Instead of storing blobs inside of a database..which in my opinion is the harder/less inefficient way to do this...what I would recommend is that you store the image(s) inside of a directory, store the image path inside of your database, then use that as your img source..

Hi,

If u want to display data in blob first write that data to a file

then refer that file in your current context

write to a image file

then in your image path specify that path

<img src="path" alt="PHP-generated image">

 

Other wise echo that field in a php file like image.php

header("content-type:image/png");

echo $field;

 

then point that action to your image

 

i.e <img src="image.php?id=1" alt="PHP-generated image">

AyKay47, can you share a little more guidance on how to store the image to a directory? I think your solution will work perfectly for what I'm trying to do. I'm very new to PHP, and I greatly appreciate your help.

okay here we go..say you have a folder that you will store your images in named "images" located under the root directory..."http://host.com/images"

Okay now say you uploaded a picture into the "images" directory named "test.jpg"

What you would insert into the database field where your image paths are stored is  "/images/test.jpg"

Then when you are ready to extract that image path you would do something like this..

 

$query = mysql_query("SELECT image_path FROM table_name WHERE something = 'something'"); //insert correct table/field names
$row = mysql_fetch_array($query, MYSQL_ASSOC);
$image_path = $row['image_path'];
print "<img src='$image_path' />";

 

If you want to display more then one image, use a while loop...

you will need a form with the enctype set to "multipart/form-data" with an input type of "file" so..

 

<form method="POST" action="#" enctype="multipart/form-data">
<input name="image" type="file" />
</form>

 

you will grab this file with the $_FILES array instead of the $_POST array here..

 

then you will move the uploaded to file to a directory of your choosing using move_uploaded_file and store that file path into your db

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.