3
I’m making a system where the user can post images, texts, etc...but in the system every image posted should be uploaded to the server and the user can delete them.
With the exclusion of the server image then the posts containing such an image present error 404.
I know it is possible to display a standard image for images not found via .htaccess
but what I want is to show neither error nor standard image, simply not show the img
.
The system is thus structured:
Page home.php
<?php
ob_start('ob_gzhandler');
session_start();
header ('Content-type: text/html; charset=UTF-8');
if(isset($_GET['last_msg_id'])){
$last_msg_id = $_GET['last_msg_id'];
}
if(isset($_GET['action'])){
$action=$_GET['action'];
}else{
$action = '';
}
if($action != "get"){
?>
<div id="coisaEstranha" style="margin-top:2%;">
<?php include('load_first.php'); ?>
<div id="last_msg_loader"></div>
<?php }else{ include('load_second.php');exit();}?>
</div>
<script type="text/javascript">
$(function(){
function last_msg_funtion(){
if($('#last_msg_loader img').length){
return;
}
var ID = $(".message_box:last").attr("id");
$.post("home.php?action=get&last_msg_id="+ID, function(data){
if (data != "") {
$(".message_box:last").after(data);
}
$('#last_msg_loader').empty();
});
};
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
last_msg_funtion();
}
});
var refreshId = setInterval(function() {
// Caso scroll seja maior que 150 pixels
if($(window).scrollTop() < 150){
$("#coisaEstranha").load('load_first.php');
}
}, 60000);
});
</script>
Page load_first.php
<?php
header ('Content-type: text/html; charset=UTF-8');
$Busca = $pdo->query("SELECT * FROM posts ORDER By id DESC LIMIT 15");
$Busca->execute();
while($fetch = $Busca->fetch(PDO::FETCH_ASSOC)){
$msgID= $fetch['id'];
$msg= $fetch['content'];
?>
<div id="<?php echo $msgID; ?>" class="message_box" >
<div>
<div id="xiao"><?php echo $msg; ?></div><!-- ESTA STRING TRÁS A POSTAGEM! -->
<input id="id_post" type="hidden" value="<?php echo $id_post;?>">
</div>
</div>
<?php
}
?>
Page load_second.php
<?php
header ('Content-type: text/html; charset=UTF-8');
$last_msg_id=$_GET['last_msg_id'];
$Busca = $pdo->query("SELECT * FROM posts WHERE id < '$last_msg_id' ORDER By id DESC LIMIT 15");
$Busca->execute();
while($fetch = $Busca->fetch(PDO::FETCH_ASSOC)){
$msgID= $fetch['id'];
$msg= $fetch['content'];
?>
<div id="<?php echo $msgID; ?>" class="message_box" >
<div>
<div id="xiao"><?php echo $msg; ?></div><!-- ESTA STRING TRÁS A POSTAGEM! -->
<input id="id_post" type="hidden" value="<?php echo $id_post;?>">
</div>
</div>
<?php
}
?>
The correct would be to test via PHP if the image exists, for example by testing with
file_exists
, depends on how your structure looks, more if you do it in your CSSimg[src=""]{display:none;}
, images with attributessrc
voids will not be displayed, see http://jsfiddle.net/9vm8761c/– abfurlan
The images come from DB because they are saved with the img tag and its respective src...I tried to use your example of Jsfiddle but it did not work in a global way nor attributing exclusively to the ID of the div that displays the posts :(
– Lauro Moraes
Show an output of your code as the tag
img
.– abfurlan
The rendered image is simple I make no changes if I do not limit the width to use the maximum available inside the parent div which is limited in pixels...ex: 420px. <img src="path/image.png" width="100%">
– Lauro Moraes
Just a touch, Lauro, your question has code too not related to the problem. Gives a check on how to do Minimum, Complete and Verifiable Example.
– brasofilo
Thanks for the "touch', initially I put no bad code I think the staff did not understand how to return and structure my code...when I get to the PC again I will try to clean the classes in Divs to get more "lean".
– Lauro Moraes
It would not only be making a conditional checking the existence of the image before the (echo $img) <- example ?
– HiHello
Unfortunately not @Zebradomal ...the "$" string that brings the content of the post brings numerous elements and there may be several images not only one.
– Lauro Moraes
Please indent and clear your code at all times. It’s better for you to understand and fix the code, and help those who want to help you, because you don’t need to decipher the logic of the program.
– brasofilo