简体   繁体   中英

How I will store image folder path into the MYSQL Database and display the image in a webpage via PHP and XAMPP?

My image path in C:\\xampp\\htdocs\\leadstart\\Bestleads\\landing\\Health\\new\\img\\logo.png

My Database imgid,companyid,cimage1

I want to insert above image path to cimage1 and display that image in my webpage via PHP

and my PHP code

<?php
        if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $query1 = mysqli_query($connection,"SELECT cimage.cimgid,cimage.companyID,cimage.cimg1 FROM cimage where companyID=$id");

        while ($row2 = mysqli_fetch_array($query1)) {

         <?php 
    echo '<img src="data:image/png;base64,'.base64_encode($row2['cimg1'] ).'"/>'; ?>

                            ?><!-- Displaying Data Read From Database -->


                            <?php
                }
            }


  ?>               

when you upload image,you must save this image to a folder in your project directory and then save this path to your database for example your path is: C:\\xampp\\htdocs\\leadstart\\Bestleads\\landing\\Health\\new\\img\\logo.png

save logo.png to your database and when you need to view this

    <?php
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $query1 = mysqli_query($connection,"SELECT cimage.cimgid,cimage.companyID,cimage.cimg1 FROM cimage where companyID=$id");
    while ($row2 = mysqli_fetch_array($query1)) {
?>
       <img src="http://127.0.0.1/leadstart/Bestleads/landin/Health/new/img/<?php echo $row2['cimg1'] ?> "/>
        <!-- Displaying Data Read From Database -->
        <?php
   }
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM