how to store & get file from database using codelgniter php & my sql - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, September 21, 2022

how to store & get file from database using codelgniter php & my sql

i can store the file into database but can't get / display the file stored in database

the file is stored in the database but can't display from the database

i am using following code

<?php

class file_upload extends CI_Controller
{

    public function index()
    {
        echo "  <head>
        <title>Upload Image To Database</title>
      </head>
      <body>
        <!-- (A) HTML FILE UPLOAD FORM -->
        <form method='post' enctype='multipart/form-data'>
          <input type='file' name='upload' accept='.png,.gif,.jpg,.webp' required/>
          <input type='submit' name='submit' value='Upload Image'/>
        </form>";

        if (isset($_FILES['upload'])) 
        {
          $imgname=$_FILES["upload"]["name"];
          $data["img_name"]=$_FILES['upload']['name'];
          $data["img_data"]=file_get_contents($_FILES["upload"]["tmp_name"]);
          $this->db->insert('images',$data);
          $data=$this->db->query('select * from images where img_name="$imgname"');
          foreach ($data->result() as $row)
          {
            print_r($row->img_data);
            echo "<img src='data:image/jpg;charset=utf8;base64, ";
            echo "base64_encode($row->img_data)";
            echo "height=100 width=100>";
          }

        }
    }  
}

?>


source https://stackoverflow.com/questions/73791047/how-to-store-get-file-from-database-using-codelgniter-php-my-sql

No comments:

Post a Comment