title: Upload and Save File Image as Bytea Data Type in laravel Postgresql
body: <p>I want to save image file into database as <strong>byte</strong> data type. I use framework <strong>laravel 8</strong>.</p>
  <pre><code>public function store(Request $request){
     $this-&gt;validate($request, [
          'file' =&gt; 'required|mimes:png,jpg,jpeg'
      ]);
  
     $file = addslashes($request-&gt;file('file'));
     $image_file = pg_escape_bytea(file_get_contents($file));
  
     $file = new File;
     $file['member_id'] = $request-&gt;session()-&gt;get('id');
     $file['file'] = $image_file;
     $file-&gt;save();
  }
  </code></pre>
  <p>The image file can already be stored in the database but when I download the image file from the database if the uploaded file has a <strong>.jpeg</strong> extension then the result is like this..</p>
  <p><strong>result</strong> : <a href="https://i.stack.imgur.com/POhY4.png" rel="nofollow noreferrer"><strong>enter image description here</strong></a></p>
  <p>And if the uploaded file has an extension other than <strong>.jpeg</strong> then the result will be like this..</p>
  <p><strong>result</strong> : <a href="https://i.stack.imgur.com/mFkon.png" rel="nofollow noreferrer"><strong>enter image description here</strong></a></p>
  <p>How to fix this problem? I want the image file to still look good when downloaded.
  Please help me...</p>