Jump to content

How to display user images on the front end


LAPS
 Share

Recommended Posts

I would like to publicly display image files of users e.g. a profile picture on the front end and I've searched the forum without much success to find a satisfactory solution for my case, probably the most common one.

The problem in displaying user images is that the user pages are located under PW Admin > Access > Users, which prevent image files to be loaded on the front end from the related access-restricted assets/files folder.

In my case, I've the profile_picture Image field in the user template and I cannot move the user pages outside PW Admin > Access > Users.

How did you solve this?

 

P.S.: I'm sure this is a common case for many PW developers and can be useful for PW newcomers, and I hope answers to this topic will be so good to many people that, perhaps, I'll need to change the title of this topic to something like "How to display user images on the front end (The Ultimate Guide)".

Link to comment
Share on other sites

@LAPS

14 hours ago, LAPS said:

In my case, I've the profile_picture Image field in the user template and I cannot move the user pages outside PW Admin > Access > Users.

How did you solve this?

Use the user page as a normal page. Any user fields can be shown if you have not set a ban in the template.

<?php
    $usr = $users->get('id='.$user_id);
    if(empty($usr->photo)){
        echo "Photo empty";
    }else{
        echo "<img src='",$usr->photo->httpUrl,"' />";
    }
?>    

 

Link to comment
Share on other sites

@Andy my problem is not related to check if the users have or not have the profile image set but to publicly display their image file. Because the user pages are located under PW Admin > Access > Users, (normally) their profile image is not accessible to the public, and I would like to make those images publicly visible the right way.

BTW I'm using LoginRegisterPro features to allow users to edit their profile image.

Link to comment
Share on other sites

@LAPS

On 2/24/2023 at 12:26 PM, LAPS said:

@Andy my problem is not related to check if the users have or not have the profile image set but to publicly display their image file. Because the user pages are located under PW Admin > Access > Users, (normally) their profile image is not accessible to the public, and I would like to make those images publicly visible the right way.

BTW I'm using LoginRegisterPro features to allow users to edit their profile image.

I too use LPR to add pictures to user profile.

Usually the user's image files are in the user's folder. As example: https://mysite.pw/site/assets/files/41/cot.jpg

And such pictures are available to everyone, unless you specify otherwise. 

You can change this behavior in the user template by enabling access control.

usersccessimage.thumb.jpg.d9a0a4c72ee7f8acc3a861897513824a.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...