I’m trying to allow users to upload a profile image on their user profile editing page, here’s the code for the upload form:
function add_extra_profile_fields($user) {
$output = '<h3>صÙرة اÙÙ
ستخدÙ
</h3>
<table class="form-table">
<tr>
<th><label for="twitter">صÙرة اÙÙ
ستخدÙ
</label></th>
<td>
<img class="video_author_img" src="'.ms_user_img_single_php($user->ID, false).'" />
<input type="file" id="admin_user_photo" name="admin_user_photo" class="form-text" /><br />
<span class="description">ÙØ£Ùض٠ÙتÙجة Ùرج٠استخداÙ
صÙرة 90px ÙÙ 90px - اÙØجÙ
اÙØ£Ùص٠2 Ù
Ùجا</span>
</td>
</tr>
</table>';
echo $output;
}
add_action('edit_user_profile', 'add_extra_profile_fields');
add_action('show_user_profile', 'add_extra_profile_fields');
The next function should be saving the uploaded image and handle cropping and placing it with another function:
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
// User image upload
$allowedTypes = array('image/gif', 'image/jpeg', 'image/png');
if (in_array($_FILES["admin_user_photo"]["type"], $allowedTypes) && ($_FILES["admin_user_photo"]["size"] < 1048576)){
ms_upload_crop_image('admin_user_photo', $user_id, '../../uploads/user_images/', 90, 90);
}
}
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
I also changed the enctype of the form with jquery:
$('form#your-profile').attr('enctype', 'multipart/form-data');
The problem is that the browser doesn’t even upload an image as if the field doesn’t exist, any idea what the problem is?
You should change two parametres in your-profile form, not one. May be it would help:
And i suggest you to use ready plugin for this purpose, called Add local avatar(http://wordpress.org/extend/plugins/add-local-avatar/) Or if you insist on using your own code, then just download the plugin and investigate it’s simple source code. Compare them and find your mistakes.