简体   繁体   中英

How to ?Switching a Default profile picture to a user inserted one

When A user is logged in the header displays a couple of icons that redirects them to different area's of the site, also it displays the users profile picture, given a user has uploaded one,

the question is; how can I display the default picture when a user hasn't uploaded a picture?

now it just shows a 'broken'image icon that is generally displayed when a file isn't found.

I've tried the following code, but that obviously didn't work.. Does anybody have a solution? (yes I'm new to coding)

  if ($loggedin)
{
 echo  "<header><div class='container'><a href='index.php'><img 
 class='image' 
 src='img/Vlindr-logo.png' alt='Vlindr logo2'  ></a></div>" .
 "<br><div class='search_box'><form action='search.php' method='GET' 
id='search'><input type='text' name='q' size='60' 
placeholder='Zoeken&hellip;'>
 </form></div> <nav> <ul>" .


     "<li><a href='messages.php'><i title='Berichten' class='email'></i></a>
</li>"       .

     "<li><a href='chat.php'><i title='Chatten' class='chat-icon'></i></a>
 </li>"       .
     "<li><a href='index.php'><i title='Matches' class='lover-icon'></i></a>
</li>"       .



     "<li><a href='friends.php'><div class='friend' title='Vrienden'></div>
 </a></li>"         .

      "<li><a href='members.php'><i title='De VLINDRTuin' class='tuin-icon'>
 </i></a></li>"         .
     "<div class='dropdown1'><li><a class='dropbtn1' href='members.php?
view=$user'>".if (file_exists("uploads/$user.jpg")) 

echo "<img 
class='profile-
icon' src=uploads/$user.jpg title='Mijn Profiel'>" else { echo "<img 
id='img' 
style=max-width:50px; src='uploads/default.jpg' align='left' /><h3 
 class='user-
 show'>$user</h3><br>";} .
       "</a></li>" .
       "<div class='dropdown-content1'> " .
       "<br><li><a href='profile.php'>Profiel Aanpassen</a></li><br> " .
       "<li><a href='logout.php'><div id='afmelden' class='hidden'>
 </div>Afmelden</a></li><br><br></div>" .


     "</ul></nav></header><br>";
  }

Solved it,

by creating a function.

 if ($loggedin)
 {
 echo  showUserSmall($user);
 }
 else
 {
  echo (......................);

And than the included function.php

   function showUserSmall($user)
   {
    {
    if (file_exists("uploads/$user.jpg"))
      echo "<header><div class='container'><a href='index.php'><img 
 class='image' src='img/Vlindr-logo.png' alt='Vlindr logo2'  ></a></div>" .
    "<br><div class='search_box'><form action='search.php' method='GET' 
id='search'><input type='text' name='q' size='60' 
 placeholder='Zoeken&hellip;'></form></div> <nav> <ul>" .


           "<li><a href='messages.php'><i title='Berichten' class='email'>
 </i></a></li>"       .

           "<li><a href='chat.php'><i title='Chatten' class='chat-icon'></i>
  </a></li>"       .
           "<li><a href='index.php'><i title='Matches' class='lover-icon'>
 </i></a></li>"       .



           "<li><a href='friends.php'><div class='friend' title='Vrienden'>
 </div></a></li>"         .

            "<li><a href='members.php'><i title='De VLINDRTuin' class='tuin-
  icon'></i></a></li>"         .
           "<div class='dropdown1'><li><a class='dropbtn1' 
  href='members.php?view=$user'> <img class='profile-icon' 
  src=uploads/$user.jpg title='Mijn Profiel'></a></li>" .
             "<div class='dropdown-content1'> " .
             "<br><li><a href='profile.php'>Profiel Aanpassen</a></li><br> " 
   .
             "<li><a href='logout.php'><div id='afmelden' class='hidden'>
   </div>Afmelden</a></li><br><br></div>" .


                "</ul></nav></header><br>";


    else {
   echo "<header><div class='container'><a href='index.php'><img 
  class='image' src='img/Vlindr-logo.png' alt='Vlindr logo2'  ></a></div>" .
   "<br><div class='search_box'><form action='search.php' method='GET' 
 id='search'><input type='text' name='q' size='60' 
placeholder='Zoeken&hellip;'></form></div> <nav> <ul>" .


       "<li><a href='messages.php'><i title='Berichten' class='email'></i>
 </a></li>"       .

       "<li><a href='chat.php'><i title='Chatten' class='chat-icon'></i></a>
</li>"       .
       "<li><a href='index.php'><i title='Matches' class='lover-icon'></i>
</a></li>"       .



       "<li><a href='friends.php'><div class='friend' title='Vrienden'>
 </div></a></li>"         .

        "<li><a href='members.php'><i title='De VLINDRTuin' class='tuin-
 icon'></i></a></li>"         .
       "<div class='dropdown1'><li><a class='dropbtn1' href='members.php?
  view=$user'><img id='img' class='profile-icon' src='uploads/default.jpg' 
  align='left' /></a></li>" .
         "<div class='dropdown-content1'> " .
         "<br><li><a href='profile.php'>Profiel Aanpassen</a></li><br> " .
         "<li><a href='logout.php'><div id='afmelden' class='hidden'>
    </div>Afmelden</a></li><br><br></div>" .


        "</ul></nav></header><br>";



 }


       }
         }

There probably is a more elegant solution out there, so if somebody has one, I am open to learning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM