Upload local photo feature in commentics project:
1. Add new field name like 'avatar' VARCHAR(255) in 'comment' data table
2. Create new folder with name as 'user_avatar' in 'images' folder
3. Add new define in /includes/language/english/form.php
cmtx_define('CMTX_LABEL_AVATAR', 'Avatar');
4. /includes/template/form.php
- Add enctype="multipart/form-data" to form tag
- Add new code at line 807
<?php
function cmtx_output_avatar(){
global $cmtx_default_avatar, $cmtx_set_avatar_value;
if (isset($cmtx_set_avatar_value) && !empty($cmtx_set_avatar_value) && cmtx_setting('state_name') == 'hide') {} else {
?>
<div class="cmtx_height_between_fields"></div>
<label class="cmtx_label">
<?php echo CMTX_LABEL_AVATAR; ?>
</label>
<input type="file" name="cmtx_avatar" id="cmtx_avatar" class="cmtx_field cmtx_text_field cmtx_avatar_field" title="<?php echo CMTX_LABEL_AVATAR; ?>" />
<?php
}}
?>
- Add new code after line 818 above cmtx_output_name();
cmtx_output_avatar();
5. /includes/app/processor.php
- Add new code at line 517 and 571 after add comment query
if($cmtx_comment_id>0){
if($_FILES['cmtx_avatar'] != ''){
$date = new DateTime();
$time_upload = $date->format('YmdHi');
$cmtx_folder = cmtx_setting('commentics_folder');
$path = $cmtx_folder.'/images/avatar/';
$new_file_name = $time_upload."_".$cmtx_comment_id."_avatar.jpg";
$upload_file = $path.$new_file_name;
move_uploaded_file($_FILES['cmtx_avatar']['tmp_name'], $upload_file);
@chmod('../'.$upload_file, 0777);
cmtx_db_query("UPDATE `" . $cmtx_mysql_table_prefix . "comments` SET `avatar`='".$new_file_name."' WHERE id='".$cmtx_comment_id."'");
}
}
6. /includes/functions/comments.php
- Add new value like $comments['avatar'] at line 51 and line 79
- Add new param as $avatar in last of cmtx_generate_comment function at line 161
- Update code at line 213 //Display gravatar
if (cmtx_setting('show_gravatar')) {
$avatar_name = isset($avatar)&&!empty($avatar)?$avatar:'avatar-blank.jpg'; ---> Change avatar-blank.jpg to blank image avatar
$cmtx_folder = cmtx_setting('commentics_folder');
$cmtx_box .= '<div class="cmtx_gravatar_block">';
$cmtx_box .= '<img src="../'.$cmtx_folder.'/images/avatar/'.$avatar_name.'" alt="'.$name.'" title="'.$name.'" width="'.cmtx_setting('gravatar_size').'"/>';
$cmtx_box .= '</div>';
$cmtx_box .= '<div style="clear: right;"></div>';
$cmtx_box .= '<div style="margin-left:' . (cmtx_setting('gravatar_size') + 5) . 'px;">';
}
I am the developer of Vietnam. I speak English not good but I hope will help you.