Store Image in MySQL

How to store image in MySQL database via PHP?

Questions by kirangona

Showing Answers 1 - 4 of 4 Answers

gmanon

  • Feb 2nd, 2010
 

The best way to store images into MySQL is by storing the image location as a charater string.

If you need to manipulate the image, then, the best way is to copy the image as a bynary.

$iname=$_FILES['img1']['name'];
    $fp=fopen($_FILES['img1']['tmp_name'],r);
    $con=fread($fp,filesize($_FILES['img1']['tmp_name']));
       
    mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("db1");
    $con=addslashes($con);
    $sqlstt="insert into tbl_img values('$iname','$con')";
    if(mysql_query($sqlstt))
        echo "Image uploaded";
    else
        echo "Failed ";

  Was this answer useful?  Yes

abc

  • Sep 12th, 2011
 

Code
  1. span style="color: #0000ff;">'img1']['name''img1']['tmp_name''img1']['tmp_name'"localhost","root","""db1""insert into tbl_img values('$iname','$con')""Image uploaded""Failed ";

  2.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions