Page 1 of 1

how to use if(file_exist){function for images plz help }

Posted: Sat May 09, 2015 5:35 am
by aliraza1697
I have a problem when I post into my site without image it shows an image error how to do that if image exist show else don't show image place in post
here below is coding

Code: Select all

 $insert_post="insert into posts (post_title,post_image,post_desc)
  values('$post_title','$post_image','$post_desc',)";
  
  $query = "select * from posts order by rand() limit 0,8";
  
$run = mysqli_query($con, $query);

while ($row=mysqli_fetch_array($run)){
	
	$title = $row['post_title'];
	$image = $row['post_image'];
	$desc = $row['post_desc'];

	
      <h2>  <?php echo $title; ?>    </h2>

<br>

<center><img src="images/<?php echo $image; ?>" width="600" height="250"/></center>

<p>  <?php echo $desc; ?>      </p>
help me if you can
thanks

Re: how to use if(file_exist){function for images plz help }

Posted: Sat May 09, 2015 6:57 am
by Celauran
Sounds like you've got the right idea, but I don't see file_exists in your code.

Code: Select all

<?php if (file_exists('images/' . $image)): ?>
    <img src="images/<?= $image; ?>">
<?php endif; ?>

Re: how to use if(file_exist){function for images plz help }

Posted: Sat May 09, 2015 9:53 am
by aliraza1697
thanks bro