Here is the code.. <img width="288" height="231" src="uploads/<?=$Threaddata['image'] ;?>" alt="<?=$Threaddata['username'] ;?>"/> Code (markup): here, this one shows the image if a user uploads an image, im trying to add a "php else function" feature where if the user doesnt upload an image a default image will be displayed. Please help out, Thanks in advance
<?php if ($Threaddata['image']) { ?> <img width="288" height="231" src="uploads/<?=$Threaddata['image'] ;?>" alt="<?=$Threaddata['username'] ;?>"/> <?php } else { ?> <b>something here</b> <?php } ?> PHP:
I have tried it, it results no error, but it not showing anything when i put the code. I tried to put an image between <b> ...</b> code.
<?php if ($Threaddata['image']) { ?> <img width="288" height="231" src="uploads/<?=$Threaddata['image'] ;?>" alt="<?=$Threaddata['username'] ;?>"/> <?php } else { ?> <img width="288" height="231" src="default_avatar.jpg" alt="<?=$Threaddata['username'] ;?>"/> <?php } ?> PHP:
If your still having problems, try using, file_exists <?php $image_file = dirname(__FILE__) . '/uploads/' . $Threaddata['image']; if (file_exists($image_file)) // checks the upload directory for the image { ?> <img width="288" height="231" src="uploads/<?=$Threaddata['image'] ;?>" alt="<?=$Threaddata['username'] ;?>"/> <? } else { ?> // not found shows a default image <img width="288" height="231" src="uploads/default.jpg" alt="default.jpg"/> <? } ?> PHP: