Mysql
 sql >> Base de données >  >> RDS >> Mysql

l'image n'est pas extraite de la base de données en utilisant le chemin

Essayez ceci et comparez avec le vôtre, je ne sais pas si cela fonctionne car je n'ai pas testé, mais cela devrait.

upload.php

include('config.php');

if ($_FILES["file"]["error"] > 0 )
{
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
  else
{
    $filename  = basename($_FILES['file']['tmp_name']);
    $ext = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);

    $new_file_name = md5($filename).'.'.$ext;

    $final_save_dir = $_SERVER['DOCUMENT_ROOT'].DS.'www'.DS.'images'.DS;
    if(move_uploaded_file($_FILES['file']['tmp_name'], $final_save_dir . $new_file_name)) 
    {
        echo "Uploaded";
    } 
    else 
    {
       echo "File was not uploaded";
    }

    try
    {
        $stmt = $conn->prepare("INSERT INTO imgdb ( image ) VALUES ( ? ) ");
        $stmt->bindParam('1', $new_file_name, PDO::PARAM_STR);
        $conn->errorInfo();
        $stmt->execute();
    }
    catch (PDOException $e) 
    {
      echo 'Database Error'.$e->getMessage();
    }
}

récupérer.php

<?php
include('config.php');
ini_set('display_startup_errors',1); 
ini_set('display_errors',1);
error_reporting(-1);

try
{
      $stmt = $conn->prepare("SELECT * FROM imgdb WHERE id = 3");
      $conn->errorInfo();
      $stmt->execute();

       while($row = $stmt->fetch(PDO::FETCH_ASSOC))
        {
            echo "<img src='images/".$row['image']."' height='100' width='100'/>"; 
        }
} 
catch (PDOException $e) 
{
     echo 'Database Error'.$e->getMessage();
}