将图像和信息存储到数据库中并使用MySql Query检索以使用PHP显示

I want to store some information in the form and the image into database.

For Example:

    <form name="form1" enctype="multipart/form-data" method="post" action="do_send.php">
  <label>
  <input type="text" name="name" id="name" />
  </label>

<label>

  <input type="text" name="age" id="age" />
  </label>


  <label>
  <input type="email" name="email" id="email" />
  </label>

  <label>
  <input type="file" name="my_file" />
  </label>
  <label>

  <input type="submit" name="button" value="Submit" />
  </label>
</form>

I want to store all this into database.I can store the data in the database but don't know how to store image. Kindly tell me how can i do this??

Also i want to display the data and image on another page using MySql query.

How can i do both these tasks. I am limited knowledge as i am a starter. Please guide me with code and a little bit of explanation.

use move_uploaded_file() function

create new folder in php project directory to store images.

only store path of image in database.

$fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; $pathAndName = "uploads/".$fileName; $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); store $pathAndName variable value in database. "uploads" is a folder name.

Use buffering + imagepng.

In do_send.php you can try with something like this :

$image = imagecreatefromstring($my_file);

// start buffering
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();

$str_base64_img = base64_encode($contents);

imagedestroy($image);

In my opinion, it's not a good pratice to directly store image datas in db and base64_encode enlarge to 33% your datas.

You should be used an hosting image system and store the path to the image in your db.