1
I have a php script that already does the insertion of images in the database, as shown below:
<?php
session_start();
include "conexao.inc.php";
setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese' );
date_default_timezone_set( 'America/Fortaleza' );
$titulo = $_POST['titulo'];
$expiro = $_POST['expiro'];
$legenda = $_POST['legenda'];
$imagem = $_FILES['imag']['tmp_name'];
$tamanho = $_FILES['imag']['size'];
$tipo = $_FILES['imag']['type'];
$nome = $_FILES['imag']['name'];
if($imagem != "none"){
$fp = fopen($imagem, "rb");
$conteudo = fread($fp, $tamanho);
$conteudo = addslashes($conteudo);
fclose($fp);
$sql = $conn -> query("insert into slide values('$titulo','$legenda','$conteudo','$expiro','".date('y-m-d')."')");
if($sql){
header("location: index.php");
}
}?>
The insertion code works and it can be viewed in the database in this way:
The viewing code is below:
<?php session_start();
include "conexao.inc.php";
$sql = $conn -> query("select * from slide order by data_cri");
while($linha = $sql -> fetch(PDO::FETCH_ASSOC)){
if($cont==0){
echo "<div class='item active'><center><figure><figcaption align='center'><label>".$linha['Título']."</label></figcaption><img src='".$linha['imagem']."' alt='Erro, manutenção necessária!' /></figure></center></div>";
}else{
echo "<div class='item'><center><figure><figcaption align='center'><label>".$linha['Título']."</label></figcaption><img src=".$linha['imagem']." alt='Erro, manutenção necessária!' /></figure></center></div>";
}
}?>
The code of the related file.inc.php is this:
<?php
try{
$conn = new PDO('mysql:host=localhost;dbname=intranet', 'root', 'aniger_2017');
$conn -> exec("SET CHARACTER SET utf8");
}
catch(PDOException $e){
echo "<script> alert('Erro na conexão!'); </script>";
} ?>
The way the image is shown in the system is as follows:
It now does not show the image, it shows the alt='Error, necessary maintenance!'
– Carlos Henrique