0

I have a script that gets images from a database and displays them on exploretest.php page. I need each image to have a separate download button under each image which allows people to download that image but am unsure on how to go about this. Any help would be appreciated.

<?php
    display();

    function display(){
        $conn = mysqli_connect("localhost","root","","loginsystem");
        $sql="select * from testimage";
        $query=mysqli_query($conn, $sql);
        $num=mysqli_num_rows($query);
        for ($i=0; $i < $num; $i++) {
            $result=mysqli_fetch_array($query);
            $img=$result['image'];
            echo '<img  class="exploreimg" src="data:image;base64, '.$img.'" style="max-height:300px;max-width:300px; margin-left:50px; margin-right:50px; padding-bottom:20px; padding-top:30px;">';
        }
    }
?>
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • https://stackoverflow.com/questions/10473932/browser-html-force-download-of-image-from-src-dataimage-jpegbase64 – Lou Apr 30 '18 at 20:06
  • Possible duplicate of [Browser/HTML Force download of image from src="data:image/jpeg;base64..."](https://stackoverflow.com/questions/10473932/browser-html-force-download-of-image-from-src-dataimage-jpegbase64) – Calvin Nunes Apr 30 '18 at 20:50
  • It's not clear what is actually going wrong. What's the problem you're having that makes you feel like you need help? – Kyle O'Brien Apr 30 '18 at 21:40

1 Answers1

0
 echo '<a href="' . $img . '" src="data:image;base64, '.$img.'" "download="imageName"><img src="img/downloadbutton.png" alt="Download" style="max-height:50px; max-width: 100px; float: center; line-height: 10;  "/></a>';
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Derek Brown Apr 30 '18 at 22:58