title: Uploading a profile picture and displaying it
body: <p>I want users to be able to upload a profile picture (which can be <code>.jpg</code> or <code>.png</code>) and I also want this to be displayed on their profile. I have written some code, based on sources I found here, on Stackoverflow and Google. However, it does not seem to work and I can't find my mistake.</p>
  
  <p>This is the html</p>
  
  <pre><code>        &lt;form action="account_settings.php" method="POST"&gt;
              &lt;input type="file" name="profilePicture"&gt;&lt;br&gt;&lt;br&gt;
              &lt;input type="submit" value="Change!"&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>This is how to uploaded file will be processed.</p>
  
  <pre><code>&lt;?php
  include ('inc/header.inc.php');
  if(isset($_FILES["profilePicture"]["tmp_name"]) &amp;&amp; isset($_FILES["profilePicture"]["name"])) {
      $ext = pathinfo($_FILES['profilePicture']['name'], PATHINFO_EXTENSION);
      $name = $_SESSION['user_login'];
      $tmp_name = $_FILES["profilePicture"]["tmp_name"];
      if($ext == 'png' || $ext == 'jpg') {
           if (isset($tmp_name)) {
              if(!empty($tmp_name)) {
                  $location = '../profielfotos/';
                  $full_name = $name.'.'.$ext;
                  if(move_uploaded_file($tmp_name, $location.$full_name)) {
                      echo 'Photo uploaded!';
                  }
                  Down here are just some else statements with error reports.
  </code></pre>
  
  <p>The code below is used to display the image. I have tested it by putting an image in the profile pictures folder and it did display the image. However, there is still a problem. People are allowed to upload <code>.jpg</code> or <code>.png</code>, how can I make the website display the picture (find the profile picture with the right extension).</p>
  
  <p>I have put this code inside the <code>src</code> attribute of the <code>&lt;img&gt;</code>tag.</p>
  
  <pre><code>&lt;?php if ($handle = opendir('profielfotos/')) {
      $file = mysql_real_escape_string($_GET['u']);
      echo 'profielfotos/'.$file.'.png'; 
  }
  closedir($handle); 
  </code></pre>
  
  <p>I hope someone can help, thanks in advance!
  ps. this is my first post ever on stack overflow :-D!</p>