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

Is php faster than javascript?

503


Is it easy to learn wordpress?

530


What is the method to execute a php script from the command line?

548


Which function you can use in php to open a file for reading or writing or for both?

551


What is the correct and the most two common way to start and finish a php block of code?

521






What's the output of the ucwords function in this example?

546


Is php 7 backwards compatible?

591


Difference between get and post method.

543


How can you pass a variable by reference?

551


Tell me what are the functions to be used to get the image's properties (size, width and height)?

531


How to include a file to a PHP page?

584


Why print_r is used in php?

527


Can I use node js with php?

525


Is empty java?

529


Tell me how is it possible to know the number of rows returned in result set?

542