Hi,
I want to upload an image ito database and display image in
a table in php
how it is possible

Answer Posted / sarita

make a folder upload in ur directory and to the following
coding:::
if (($_FILES["file"]["type"] !== "image/jpeg") &&
($_FILES["file"]["type"] !== "jimage/peg") &&
($_FILES["file"]["type"] !== "image/png") &&
($_FILES["file"]["type"] !== "image/gif") &&
($_FILES["file"]["type"] !== "image/bmp"))
{
echo "<center><b><font color=#ff0000>Invalid file type,
please select an image with extension .jpg,.gif,.bmp
or.peg</font></b></center>";
}
else
{

move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);

echo ""."Stored in: "."" . "upload/" .
$_FILES["file"]["name"]."<br>";

$imgname=$_FILES["file"]["name"];
$tmpname=$_FILES["file"]["tmp_name"] ;
$type=$_FILES["file"]["type"];
$size=$_FILES["file"]["size"];
$upload= "upload/" . $_FILES["file"]["name"];

$handle = fopen("$upload", "rb");
$img = fread($handle, filesize($upload));
fclose($handle);
//die($img);

$img = base64_encode($img);


$doe=$_POST['date'];
$result1=mysql_query("insert into tbl_album
values('','".$_POST['aname']."','','$type','$size','$imgname','$doe','".$_POST['shortdes']."','".$_POST['longdes']."')")
or die(mysql_error());


if($result1)
{
echo "<center><b><font color=#0099FF>Album added
Successfully</font></b></center>";
}








$ingname is saved in ur database and folder upload
successfull...u cn change the name of folder acc to u.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between html and php?

706


Which is true about the singleton design pattern?

717


How many data types are used by php?

713


What is the purpose of $_ session?

700


Explain me what is the importance of "method" attribute in a html form?

710


What is the purpose of the '.frm' file extension? What do thes file contain?

708


What is csrf cookie?

674


What is session and why do we use it?

773


Tell us how to set cookies in php?

700


Explain which cryptographic extension provide generation and verification of digital signatures?

772


Which character is used to match exactly one character?

758


What new features php7 has in store for us?

750


What is a php 5?

737


What is strlen function in php?

739


What are the ways to define a constant in php?

741