I originally posted this topic under the MOD section of the phpBB official forums and I do not know if you all can help me out but here is what I am trying to achieve:
I would like to add the possibility to change the avatar from my main web site (not on the forum) through URL and uploaded image.
So far I was able to find code to get the avatar:
- Code: Select all
include("./phpBB3/includes/functions_display.php"); $avatar_img = get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']); echo $avatar_img;
I was also able to get this working (for URL upload):
- Code: Select all
$sql_ary= array ( 'user_avatar_type'=> AVATAR_REMOTE // Not local, not chosen from gallery , 'user_avatar'=> 'http://www.anysite.com/theavatar.jpg' // Link to image , 'user_avatar_width'=> 100 // Dimension in pixel... , 'user_avatar_height'=> 100 // ...same ); $sql= 'UPDATE '. USERS_TABLE. ' SET '. $db-> sql_build_array( 'UPDATE', $sql_ary ). ' WHERE user_id= '. $user_id; // Member whom to assign new avatar $db-> sql_query( $sql );
But I was unable to find a way to get the "Upload from your machine" option to actually work.
It is probably a lot similar to what I posted above regarding URL upload but I saw that the files I upload through the forum are renamed and I do not know how I could do that exactly as phpBB to make them working properly (the files uploaded seems to be renamed in ./phpBB3/includes/functions_upload.php).
I do know that:
0 = AVATAR_REMOTE
1 = AVATAR_UPLOAD
2 = AVATAR_GALLERY
So I would probably need to change 'user_avatar_type' to AVATAR_UPLOAD. Rename the file as phpBB would do, upload it to ./phpBB3/images/avatars/upload/ and get the image name after the upload process to be able to use it in my UPDATE statement.
Can anyone give me a hand with that please? I must admit that my PHP knowledge is at a medium level and I would mainly need help with the upload and get the file name back part. I wanted some tips before actually trying anything, as someone probably already did this or got a better idea as to how to do it.
The code would probably look like:
- Code: Select all
include("./phpBB3/includes/functions_upload.php"); $source_file = '' //I would fill this with the path to the file I want to upload $file_uploaded = function local_upload($source_file, $filedata = false); //I am unsure what the function actually returns. This would be done when I submit my form. echo $file_uploaded->get('filename'); //I am unsure about this, the same reason as the line above. $sql_ary= array ( 'user_avatar_type'=> AVATAR_UPLOAD , 'user_avatar'=> $file_uploaded , 'user_avatar_width'=> '' //I am unsure about this, probably a property of $file_uploaded> , 'user_avatar_height'=> '' //I am unsure about this, probably a property of $file_uploaded> ); $sql= 'UPDATE '. USERS_TABLE. ' SET '. $db-> sql_build_array( 'UPDATE', $sql_ary ). ' WHERE user_id= '. $user_id;
Thanks a lot for your time and help.