简体   繁体   中英

Get Image from Database with php mysql

I am trying to get an image from my database I use the following code:

  <?php   
    $image_qry=mysqli_query($mysqli,"SELECT * FROM Benutzer");
    $image=mysqli_fetch_assoc($image_qry);
    $get_image=$image['Profilbild']; //This should contain the picture
    header("Content-type: image/jpeg"); 
    echo $get_image;
     ?>

Here is my database structure:

用户

Please help me and tell me how can i output this picture in a commun <div> element

Instead of storing your image inside of the database create a upload folder then just store the image name into the database and when you want to call it just add the name at the end.

<?php   
    $image_qry=mysqli_query($mysqli,"SELECT * FROM Benutzer");
    $image=mysqli_fetch_assoc($image_qry);

    $link = directory of image;
    $get_image=$link.$image; //This should contain the picture

    echo file_get_contents($get_image);
?>

upload script:

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}

reference:

http://www.w3schools.com/php/php_file_upload.asp

我认为您得到的结果数组包含索引0中的第一行

$get_image=$image[0]['Profilbild']; 

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