Hello,

I am building a page that will display the logged in users information, primarily their uploaded avatar and/or profile image. I successfully created the upload script that will take the image and move it to a folder called "uploads" in my directory. I even achieved the upload automatically renaming the file to something unique, like the user's email address.

Now I have a page called "my_account.php" in which I want to display that image, but not all images in the folder. I only want the one that is unique to the current logged in user. My method of achieving this could be totally off, which is why I would appreciate any help I can get.

My current upload script:
Code:
// Get File Extension
function getExtension($str){
     $i = strrpos($str,'.');
     if(!$i){
          return '';
     }
     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
}
// File Data
if(($_FILES['image']['type'] == 'image/gif') || ($_FILES['image']['type'] == 'image/jpg') || ($_FILES['image']['type'] == 'image/jpeg') || ($_FILES['image']['type'] == 'image/png')){
     $err = 0;
     if($_FILES['image']['size'] < 500000){
          $err = 0;
     }
     else {
          $err = 1;
          $error[8] = '<span class="errors">File size is too large!</span>';
     }
}
else {
$err = 1;
$error[8] = '<span class="errors">File type not supported.</span>';
}
$fileName = stripslashes($_FILES['image']['name']);
$extension = getExtension($fileName);
$extension = strtolower($extension);
$imageName = $_POST['email'].'.'.$extension;
Then further down after some more code is the move:
Code:
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $imageName);
That seems to work perfectly for me (not saying it's the best or cleanest method), but it gets the file over to the folder I want and renames it.

Now on my "my_account.php" page, I am trying to display that image for the logged in user (who's login id is their email address as well as the images name now too). This is where I get stuck. The current code I have is this...

Code:
// Get Avatar
$dir = 'uploads/';
$myImage = $_SESSION['email'];
$image = scandir($dir);
$ignore = array('.png', '.jpg', '.jpeg', '.gif');
if(!in_array($myImage, $ignore)){
     echo '<img src="'.$dir.$myImage.'" class="avatar" />';
}
I know this isn't anywhere close to right, trust me. But hopefully I'm at least on the right track. My problem here seems to be the images extension (.png, .jpg, etc.).

If anyone has done this before or just knows the best way to achieve this the help would be tremendously appreciated!

Thanks!