Good day everyone! Anybody could give me script for uploading or inserting image into database and how to retrieve it and print it to browser

Any help would be appreciated.

Thank you in advance.

roland

Are you sure you really want to do that? I think that for most applications you will be better off storing the image in a folder on your webserver and adding the location/details of the image to the database.

Are you sure you really want to do that? I think that for most applications you will be better off storing the image in a folder on your webserver and adding the location/details of the image to the database.

Okey, thinks for your advice, but how can I do that, are there any configuration to be done in the server, could you give me a script for this?

Thank you.

Roland

If you do decide you want to store the image in a database (there are circumstances) then use a blob datatype.

I will agree that it is rare that you would want to do that outside of a data hosting site like that. Otherwise you can just store the url and output it however you want by calling it with php and tellting using the following code

echo '<img src ="'.$imgurl.'">';

That will output it as the image itself. Naturally you can add the formating to it. But I find that method INCREADIBY effective.

hey guys
i have problem somehow similtar to this, how to insert colored, formated text in db and retrieve it.
when i play with the font or anything of the text throught html editor, the text is not saved in db.

the text attribute is empty, what should i write as a script.

thanks

sam

I store things in it using full text

I store it using a variable like so

$value = '<b><center><fontcolor= "blue">This is the formated text</b></center></font>';
$query = "instert into table ('$value')";
mysql_query($query);


I use formated text alot for my forum.

Also it is possible to simply output it the text using concatenated strings with php. Its up to what you're using the text for.

Member Avatar for Rhyan

I store things in it using full text

I store it using a variable like so

$value = '<b><center><fontcolor= "blue">This is the formated text</b></center></font>';
$query = "instert into table ('$value')";
mysql_query($query);


I use formated text alot for my forum.

Also it is possible to simply output it the text using concatenated strings with php. Its up to what you're using the text for.

This is one way, however you will be unable to use this value in another place with another color settings. Instead I would recommend you store plain text data into your database and use some simple CSS rules where you need the text to be in different color.
You can make the following:
1. Store value $formatted_text = This is the text to be returned in red.
2. Retrieve it in your php page like this:

echo '<p style="color: red">'.$formatted_text.'</p>';

and you will get it right ;)

if you want you can use a class for this statement and add a lot of other formatting stored in an external file.

In case however you have some text and you want to store only one word with formatting, you better do the following:

$formatted_text = 'This is the text with <span style="color: red;">red words</span> in the middle.';

When you retrieve it in your php like this:

echo '<p>'.$formatted_text.'</p>';

you will have a paragraph with "red words" being the only red words inside the text.

If you are not familiar with CSS go to http://www.w3schools.com/ and learn it for free from the W3C. Good luck!

All u do is, use ASP. The database that I've chosen is Microsoft Access database. I could have explained it on Microsoft SQL server but I chose Access because it is inexpensive and widely available. Transition form Access to SQL Server is painless.

keep getin' this message:

1. no radio button selected.

what's wrong?

just found it..

//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>"); 
//query database
$query = "SELECT image FROM youtablename WHERE id = 10";

$result = mysql_query($query) or die('Error, query failed');
$content=mysql_result($result,0,"image");

//send pdf to requesting page
header("Content-type: application/pdf");
echo $content;

If you retrieve a .jpg file, you need use:

header("Content-type: image/jpg");

If you retrieve a .gif file, you need use:

header("Content-type: image/gif");

If you retrieve a .mid file, you need use:

header("Content-type: audio/mid");

Hey people,

I am having the biggest problem with MySQL and PHP. Basically, I have a database and I would like to store images to the database (not the images directly as BLOBS, but as paths), how do I do this?

My database structure looks like this:

Database Table: Pictures
Fields:
- PicID (Type: VarChar)
- PicName (Type: VarChar)
- PicPath (Type: VarChar)

An example entry looks like this:

- PicID = 001
- PicName = SimpsonsPic
- PicPath = C:\wamp\www\Pics\Simpsons.jpg

Now, how do I make a simple PHP webpage that displays that pic?
I have this so far, but don't know what else to add:

<?php

$con=mysql_connect("localhost","root","chopra9");
$img;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("pictures", $con);
$result = mysql_query("SELECT * FROM picturecollection");
while($row = mysql_fetch_array($result));
{
//What goes here
}
mysql_close($con);
?>

Any help would really be appreciated. Ive looked on the net for a week and havent found anything good. Thanx!!!

This will slow down ur database and this is not a good programing practice - i suggest u keep all ur files in seperate folders and from the database get the path and show it in ur application from the path.. Do let me know if you want script for this..

This will slow down ur database and this is not a good programing practice - i suggest u keep all ur files in seperate folders and from the database get the path and show it in ur application from the path.. Do let me know if you want script for this..

What you have exactly described is what I want to do. Could you please send me the script(s) and the database designs please. And if you could please, keep the code simple, so that I can understand it.

Hey, i m solved your problem, you can try it. Thankx.

<?php

$con=mysql_connect("localhost","root","chopra9");
$img;
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
  mysql_select_db("pictures", $con);
  $result = mysql_query("SELECT * FROM picturecollection");
  while($row = mysql_fetch_array($result));
  {
     echo "<img src='Pics\Simpsons.jpg'" width='50' height='50'>";
  }
  mysql_close($con);
?>

could any one help me of the answer???
thank you in advance..
Prasenjit

how i delete image from database?

could any one help me of the answer???
thank you in advance..
Prasenjit

You have reply just above your post. If you do not like that answer then do no re-open old thread and create new one

how i delete image from database?

w3schools SQL DELETE Statement

i'm still working in it........

Well could you tech me how cos i really think thats way easier.

Thanks to everybody. But i am still getting what is the method to do this thing. Can anybody help me. I am using MySQL. I want to store image in DB. I am clear on data type that is BLOB. But i do not how to create a button for user to upload images.

How insert image into mysql database and retrieve

how would i store the path of the image in the database? /img/img.jpg or with quotes round it? or another way i havnt thought of yet?

guys please start new threads when changing topics.

For the mysql images I built a simple tutorial here

for the font. use openwysiwyg

Hope this helps :)

use this example for uploading
<form enctype="multipart/form-data" action="__" method="post"></form>
<?php
$pn = $_FILES[photo][name];
$pt = $_FILES[photo][type];
$ps = $_FILES[photo];
$ptmp = $_FILES[photo][tmp_name];

$query = "insert into table_name values('','$pn','$pt','$ps')";

$result = mysql_query($query) or die('Error!');
if($result){
move_uploaded_file($ptmp,"photos/$pn");
}
?>

If you are storing images in a database there is no literal directoy so you don't have a file location. however you can always add categorys to sort it.
read my tutorial as above. it works "Out of the box". if you need it to do something different I can sort you out something :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.