title: PHP search folder for user pic set default image if nothing found
body: <p>Im using a great opensource script called <a href="https://github.com/samayo/bulletproof" rel="nofollow noreferrer">bulletproof</a> allowing users to upload a profile picture.</p>
  
  <p>The profile picture gets stored in a folder as specified. Im not using any mysql.</p>
  
  <p><strong>What I would like to do is display a default user img if user has not uploaded a profile picture.</strong> </p>
  
  <p>If he/she has uploaded a profile picture the default img will obviously get overwritten to the pic uploaded by user. </p>
  
  <p>The problem comes in on how would I display the default profile pic, if user has not uploaded anything? Keeping in mind im not using any mysql.</p>
  
  <p>When an image is uploaded it is assigned the name of the user ID, like so </p>
  
  <pre><code>&lt;img src="imgs/users/1.png" style="width:100%" height="125px"&gt;
  </code></pre>
  
  <p>Would you say it is the most efficient way to search the folder for an image match on the name userID? </p>
  
  <p>If something is found display uploaded img else display default img?  Or should I rather go a mysql route?</p>
  
  <p>Hope the question is clear, if you need any more info please drop me a comment below. Any advice and/or help appreciated.  </p>
  
  <p>EDIT: this is what I eventually came up with, probably not most efficient but does the job</p>
  
  <pre><code> function getProfilePic($userID){
  
          $filename ='imgs/users/'.$userID.'.png';
          if(file_exists($filename)){
              return $img = $userID.'png';
              exit();
          }
          $filename='imgs/users/'.$userID.'.jpg';
          if(file_exists($filename)){
              return $img = $userID.'jpg';
              exit();
          }
          else{
              return $img = 'default.jpg';    
              exit();
          }
      }
  
   &lt;img src="imgs/users/&lt;?php echo getProfilePic($userID) ?&gt;" style="width:100%" height="125px" /&gt; 
  </code></pre>