How to upload image to MySQL database and display it using php

Viewed 58

I want to have a change profile picture function using php and create an API after that. Here is the form for choosing the file:

<form class="row g-3 needs-validation formmdl" novalidate="" action="upload.php">
    <div id="alert-content" class="col-12"></div>
       <div class="col-12">
          <label for="profilePicture" class="form-label" >Change Picture</label>
    <input type="file" class="form-control1 inputbd" name="profilePicture" id="profilePicture" style=" text-indent:initial;" accept="image/x-png, image/jpeg" onfocus="focused(this)" onfocusout="defocused(this)">
</div>
                                            
  

I created an action file for the form which is the upload.php. The image must be displayed on this image element:

<div class="avatar avatar-xxl1 ">
     <img src="/assets/hub/img/bruce-mars.jpg" alt="profile_image" class="border-radius-lg shadow-sm " style="height: auto;">
</div>

Here is what I attempted to do in the upload.php file:

?php 
if (isset($_POST['submit']) && isset($_FILES['my_image'])) {
    echo "Hello"; } 
else {
    header("Loacation: profile.blade.php"); }
0 Answers
Related