I am making a system where the user can post images, texts, etc ... however in the system every image posted must be uploaded to the server and the user can delete them.
With the deletion of the image from the server, the posts that contain such an image have the 404 error.
I know that it is possible to show a default image for images not found via .htaccess
but what I want is not to show neither standard error nor image, I just do not show img
.
The system is structured like this:
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
}
?>