Apr 16, 2012

How to Upload PHP Image & Make Thumbnail Inserts for MySQL Record

,


When you offer avatar selections for users, you must upload a thumbnail image to a MySQL database from your PHP code. The "blob" data type sets the database field for image storage, so you can save a small image file to the database without filling up your database server's hard drive space.

Instructions

    • 1
      Right-click the PHP page you want to use to insert the image into the database. Click "Open With" and select your image.
    • 2
      Set up a variable that points to the image you want to upload. For instance, the following code uses "avatar.jpg":
      $img = "avatar.jpg";
    • 3
      Upload the image to the MySQL database. You must specify the data type when you upload to the database. The "blob" field data type requires specifications such as a JPG, a PNG or a GIF file. The following code inserts the file into the database:
      $query = "insert into avatars (image, type) values ('" .$img."', 'image/jpg')";
      mysql_query($query);
 

HowToYo Copyright © 2011 | Template design by O Pregador | Powered by Blogger Templates