Andrew Ferguson
Romping Around in Europe
Add User Photo
Overview
Allows adding a photo to a user profile
Compatibility
- 2.1.*
- 2.0.*
- 1.5 (in theory, not tested)
Installation
Download the file and put it in your plugins directory. In your wp-content folder, create a directory called images and make sure that it was write permissions.
Modify line 21 of /wp-admin/profile.php, adding enctype="multipart/form-data" to the form tag. So at the end of the day, line 21 should look like:
<form name="profile" id="your-profile" action="profile-update.php" method="post" enctype="multipart/form-data">
Activate plugin.
Usage
User will now be able to upload a jpg-based image. The image is uploaded and renamed to their username with a jpg extension (e.g. johndoe.jpg).
The file is located in /wp-content/images/
To use the file, simply reference its location. This can be done using an absolute reference (i.e. pointing to an image at http://www.example.com/wp-content/images/johndoe.jpg) or through PHP programming.
Example:
If you know the UserID, but not the username, you can do a simple lookup:
$userLogin= $wpdb->get_var("SELECT $wpdb->users.user_login FROM $wpdb->users WHERE $wpdb->_users.ID = ".$someUserID.");
if(file_exists(ABSPATH."wp-content/images/".$userLogin.".jpg"))
$imageURL = get_bloginfo('url')."/wp-content/images/".$userLogin.".jpg";
else
$imageURL = get_bloginfo('url')."/wp-content/images/unknown.jpg";;
echo "<img src=\"$imageURL\" />";
In the above example, an addition file, unknown.jpg, has been placed in the images directory to serve as a placeholder for users who haven’t uploaded images. You also need to specify the value of $someUserID.
Download
Latest Version:
Subscribe to RSS Feed
Thanks for the plugin but has anybody solved the bug that Yotsume mentioned: “Error: Please only upload jpg files! Your content type is”
I’m having the same problem using WP2.2. I even edited the photo in fireworks to make sure it was jpg and it still returns this error.
This plugin is ideal for what I’m trying to do, just a photo for each user that can be displayed on his profile or author page. No strange gravatar things that normal people don’t understand
Keep up the good work, Andrew!
This is for Sofia…
I found I can upload photos for my members by duplicating the line:
add_action(’show_user_profile’, ‘fergcorp_addUserFolder_addField’);
and changing the duplicated line to ‘edit_user_profile’
so you will have three lines then:
add_action(’show_user_profile’, ‘fergcorp_addUserFolder_addField’);
add_action(’edit_user_profile’, ‘fergcorp_addUserFolder_addField’);
add_action ‘personal_options_update’, ‘fergcorp_addUserPhoto_updateField’);
Hope this helps.
Martin
Oops.. One more thing Sofia..
You also have to add the:
enctype=”multipart/form-data”>
to the
Sorry, Got cut off.
Oops.. One more thing Sofia..
You also have to add the:
enctype=”multipart/form-data” (see top of this page)
to line 76 of user_edit.php file in the admin folder if using Wordpress 2.1.2.
It may be some other line in a diff version.
This is for the The Big Chorizo:
Normally the error message you get would be “Error: Please only upload jpg files! Your content type is image/pjpeg”
For a while I was getting the msg w/o the type printing out and found that I had not added the enctype=”multipart/form-data” (with a trailing greater than) to the profile.php file. Not sure if the orig. poster just forgot to type the rest ofthe error msg, but hope this helps.
p.s. had to put trailing greater than as using the symbol may cut off the comment.
Hi
I wrote a small code to automatically resize the uploaded pictures.
add this 2 functions
[php]
function calcratio($src_w, $src_h, $dst_w, $dst_h){
$ratio_orig = $src_w/$src_h;
if ($dst_w/$dst_h > $ratio_orig) {
$dst_w = $dst_h*$ratio_orig;
} else {
$dst_h = $dst_w/$ratio_orig;
}
$result=array($dst_w, $dst_h);
return $result;
}
function redimage($filename,$src_w,$src_h) {
$newsize = calcratio($src_w, $src_h, 120, 150);
$dst_im = ImageCreateTrueColor($newsize[0],$newsize[1]);
$src_im = imagecreatefromjpeg($filename);
ImageCopyResampled($dst_im,$src_im,0,0,0,0,$newsize[0],$newsize[1],$src_w,$src_h);
ImageJpeg($dst_im,$filename);
ImageDestroy($dst_im);
ImageDestroy($src_im);
}
[/php]
juste before this line :
[php]
add_action(’show_user_profile’, ‘fergcorp_addToUser_addFields’);
[/php]
And add this 2 lines :
[php]
list($width, $height) = getimagesize($final_path);
redimage($final_path, $width,$height);
[/php]
after the move_uploaded_file command :
[php]
move_uploaded_file($_FILES['photoUpload']['tmp_name'], $final_path);
chmod($final_path, 0644); // rw for owner, r for everyone else
[/php]
This code require the GD2 library. The resized size can be set on this line :
[php]
$newsize = calcratio($src_w, $src_h, 120, 150);
[/php]
Actually, the image size is 120px width and 150px height
The calcratio function will keep the image aspect when the image is resized. Hope it helps.
You can see the complete source code here : http://pastebin.com/f2002953b
Chag
I think this is better than using gravatar.. Thank you for this plugin.
to chad: tried your code but it gives me the error message even if I have no user photo.
Hi,
what error message ?
to chag: this is the error
Error:Please only upload jpg files! Your content type is
Please go back and try again.
…but I managed to avoid the error by adding
|| ($_FILES['photoUpload']['type'] == “” at the IF statement of
fergcorp_addToUser_updateFields()
I’m not sure if that’s the right solution but after adding it, now it’s working.
I still get error msg: Error: Please only upload jpg files! Your content type is. (without pjpeg), every time I hit Update Profile button. Any idea why?
Hey Andrew,
This is a great plugin. I tried using your db code to have the image show the current author’s image if you’re viewing the author but I get an error.
[code language="php"]WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
SELECT user_login FROM wp_users WHERE ID =[/code]
This is the code I put at the top of the author page:
[code language="php"]< ?php $username = $wpdb->get_var(”SELECT user_login FROM $wpdb->users WHERE ID = “.$_REQUEST['author']); ?>[/code]
I’m not sure what I could be doing wrong? I’d love to get this working because I’ve got a project that will have 6-7 authors so I’d like their images showing automatically.
Thanks
Just so everyone knows, as SOON as I posted that comment, I figured this out
Wordpress has you add this to your author page to get the current user.
[code language="php"]< ?php
if(get_query_var('author_name')) :
$curauth = get_userdatabylogin(get_query_var('author_name'));
else :
$curauth = get_userdata(get_query_var('author'));
endif;
?>[/code]
So this way, you can use codes to show the name, login name, description, ect. All I did was replace the get $username from my above comment, and replaced it with this code
[code language="html"]
[/code]
[...] it. Interested in using wordpress to power your e-commerce websites? This is the plug-in you need. Add User Photo - Andrew put together an awesome plug-in that allows all of your authors and anyone else who signs [...]
Auf Deutsch kann mit keiner bei dem Plugin helfen oder? Ich bekomme keine Fotos hochgeladen steht immer:
Error: Please only upload jpg files! Your content type is
Please go back and try again.
ich habe es mit allen jpg Datein versucht, groß klein aber nicht
@Aike:
If the MIME type is not
image/jpgorimage/jpeg, the file will not upload. It is possible to have the plugin not check the file type, however users would be able to upload any type of file at the point, which would be security risk.If you are okay with that, then change line 61 from:
if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”)){to
if(1){Hi Andrew,
After uploaded my image, I receive the following error message: “Upload error: Unable to place the user photo at: /home/restricted/home/MYSITE/public_html/wp-content/uploads/userphoto/admin.JPG.
I checked the permissions and the uploads folder settings and it seems to be ok.
Regards.
hi
I downloaded the file and made it in wp-content/plugins folder and i changed the form to encrypt=multipart/ settings in wpadmin/profile.php
after this i go and check the profile page i didnt find the field and input box in that page.pls tell me how to do it. i need to add create table for that image or how to make it work for me
Sorry andrew its working fine the person who given me the work described wrong folder anyway thanks its working great
Hi, this pluggin work fine in firefox but not in IE. and there is no profile-update.php page in wp-admin folder. thanks.
How has all of this changed with Wordpress 2.7? I see one item is different - the /wp-admin/profile.php file is actually /wp-admin/user-edit.php
Also, trying to put the author’s photo in their post - keep in mind we have multiple authors for this blog. Any advice or code to help me modify the index.php file to do this?
“I see one item is different - the /wp-admin/profile.php file is actually /wp-admin/user-edit.php”
That’s inaccurate. profile.php is a central part of the whole WP process.
I posted a detailed request for help, and it appears to have disappeared. Before I retype the whole thing, I will look and see what happens to this.
Ok, let me try this again.
I can’t edit line 21 of /wp-admin/profile.php because the file is only 20 lines long.
The complete file is below. Please tell me how I modify it to get this plugin to work.
Does this have the ability to upload more than one picture per profile? I am dying for a solution to make this happen.
no, it doesn’t