我可以';t显示默认图像


I can't display default image?

如果在特定文件夹中找到用户定义的图像,我希望显示该图像,如果没有,则显示默认图像。

<img src="user_images/<?php echo file_exists('user_images/'.$user.'.jpg')? $user.'.jpg' : 'img/logo-small.png'?>" alt="profile pic" class="userImage" />

这似乎不起作用。我哪里错了?

您需要回显/打印文件名。

尝试

<img src="user_images/<?php echo file_exists('user_images/'.$user.'.jpg')? $user.'.jpg' : 'img/logo-small.png'?>" alt="profile pic" class="userImage" />