This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Picture upload
#1

I would be nice when there is a picture upload feature instead of only the path. (upload/choose from your own computer)

A lot of people don't know how to upload a picture themselves.
Reply
#2

I agree. I've added it to the Roadmap.

Have you completed the interview?
Reply
#3
Star 

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;">';
   }
   
Big Grin  I am the developer of Vietnam. I speak English not good but I hope  will help you.
Reply
#4

Does this code work. Anyone?
Reply
#5

I ask because the step #5 does not look like you could add this code without breaking it.
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."'");


}
}
lines 515 -524 look like this:
//build the approval box
$cmtx_box = "<div class='cmtx_approval_box'>";
$cmtx_box .= "<div class='cmtx_approval_message_line_1'>";
$cmtx_box .= CMTX_APPROVAL_OPENING;
$cmtx_box .= "</div>";
$cmtx_box .= "<div class='cmtx_approval_message_line_2'>";
$cmtx_box .= CMTX_APPROVAL_TEXT;
$cmtx_box .= "</div>";
$cmtx_box .= "</div>";
$cmtx_box .= "<div style='clear: left;'></div>";
and lines 568 -577 look like this:
//build the success box
$cmtx_box = "<div class='cmtx_success_box'>";
$cmtx_box .= "<div class='cmtx_success_message_line_1'>";
$cmtx_box .= CMTX_SUCCESS_OPENING;
$cmtx_box .= "</div>";
$cmtx_box .= "<div class='cmtx_success_message_line_2'>";
$cmtx_box .= CMTX_SUCCESS_TEXT;
$cmtx_box .= "</div>";
$cmtx_box .= "</div>";
$cmtx_box .= "<div style='clear: left;'></div>";
Reply
#6

Yeah...this don't work in my Version: v2.5 (9th March 2014)
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by neosupers
01-May-2015, 06:25 AM
Last Post by huuptag2014
26-Oct-2014, 11:50 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)