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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliraza1697
Forum Newbie
Posts: 2
Joined: Sat May 09, 2015 5:17 am

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

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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; ?>
aliraza1697
Forum Newbie
Posts: 2
Joined: Sat May 09, 2015 5:17 am

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

Post by aliraza1697 »

thanks bro
Post Reply