Get Facebook user profile using their photo filename

If you find some image file saved from Facebook, you can quickly get the users profile ID and other details from the image file name. Every image saved from a Facebook profile has a unique filename such as ‘86948_8239343856_5678_n.jpg’ (this is a dummy number).

The 2nd number from left in the filename, in this case 8239343856, which is the unique profile ID of the Facebook user.

So now the Facebook profile URL for the user is The following PHP script will help you get the various details like name, username, gender and locale.

/* filename like 86948_8239343856_5678_n.jpg */
$photo_name = "PHOTO_FILENAME";

$profileId = explode("_", $photo_name);

/* filename format */
switch(count($profileId)) {
    case 6 :    $id = $profileId[2];
    case 4 :    $id = $profileId[1];
    case 3 :    $temp = array("n", "N");
                $id = str_replace($temp, "", $profileId[0]);
    default:    break;

$profileLink = "".$id;
$profileImage = "".$id."/picture?type=large";
$graphAPI = file_get_contents("".$id);
$graphJSON = json_decode($graphAPI, true);



10 thoughts to “Get Facebook user profile using their photo filename”

  1. It used to, seems not to anymore, they probably caught on. Maybe facebook cares about privacy after all?

  2. Work for me just fine.
    But only on a profile pictures, not on any picture name with numbers.

    I found a solution on the net ………. 🙂

    You can download chrome extension that do the same job:

    Now you can easily do that.

  3. it was nice tutorial. but in my case I dont have picture file name in that format. The format i have is IMG_25302073190279.jpg.
    how to trace this FB user? I have 100% sure it is from FB.
    Please send me the detail in my email or send me the profile of that picture in email. I want to know who is he.

  4. Works fine if you have older photos with the ID in them, newer photos have different numbers.

Leave a Reply

Your email address will not be published.