Posted inAjax / JavaScript / jQuery / Mysql / Mysqli / php

how to insert image in database using php? – 2 ways to insert images in mysql Example

how to insert image in database using php : In some registration or sign up HTML For via php as well as web application i required image upload. For Example: For User Profile picture upload, Your Product gallery photo upload, portfolio image etc.

how to insert image in database using php?

There are Main 2 methods to insert images in mysql database.

  • binary format insert
  • image upload in folder
  • how to insert image in database using php
    how to insert image in database using php

    Using binary format

    In this type I directly simple step by step insert the image in mysql database table using binary format.

    Using all the any types of the image upload in single folder

    In this type i upload the image in a folder as well as store the image name in MySql database table.

    For insert query to image in MySQL first i have to create a table in data base.

    CREATE TABLE `portfolio` (
    `id` int(11) NOT NULL,
    `portfolio_img` varchar(55) NOT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    

    index.php

    
    
    
        Insert Image in MySql using PHP - www.pakainfo.com
    
    
    
    

    do_upload.php

    
    

    Don’t Miss : How To Upload File/Image In CodeIgniter?

    CREATE TABLE `portfolio_img` (
    `id` int(11) NOT NULL,
    `portfolio_img` LONGBLOB NOT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
      
    

    Here we using 1 file for insert portfolio_img in MySQL:

    Simple HTML form that allow users to select the portfolio_img file they want to upload.

    Using binary format

    index.php

    
    
    
        Insert Image in MySql using PHP - www.pakainfo.com
    
    
    
    

    I hope you get an idea about how to insert image in database using php.
    I would like to have feedback on my infinityknow.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype