0
I want to know if the file is empty or not and if you do not insert a default image on the variable before inserting
This is what I have so far, I have also a part of type checking the type of session
<form role="form" method="post" enctype="multipart/form-data">
<input type="file" name="inpFile" id="inpFile" class="inputfile" />
<button type="submit" id="insert" name="insert"> Editar </button>
</form>
if (isset($_POST["insert"])) {
$file = addslashes(file_get_contents($_FILES["inpFile"]["tmp_name"]));
$username = trim($_REQUEST["username"]);
//Check if image is empty
if(empty($file)){
if($type == 1 || $type == 2 || $type == 3 || $type == 4){
//Set $file a predefined image
}
}
$sql = "INSERT INTO pratos (name, image) VALUES ('$username', '$file')";
$pdo->exec($sql);
}
This was the attempt I made trying to insert a default value
$file = "../img/prato_default.png";
I want to find a way to insert a default image and show it on another page
$pesquisa = "SELECT * FROM pratos";
$resultado_pesquisa = mysqli_query($conn, $pesquisa);
<?php while ($rows_pesquisas = mysqli_fetch_array($resultado_pesquisa)) { ?>
<img <?php echo 'src="data:image/jpeg;base64,' . base64_encode($rows_pesquisas['imagem']) . '"'; ?> class="image">
Face is not with PHP, but with pure CSS, and you might be interested https://answall.com/questions/321138/comort-do-um-stylingfor-imagem-broken-when-a-imagem-n%C3%a3o-load
– hugocsl