Intechnic
Users Developers
Home / Forums / In-Portal CMS / General In-Portal Discussions / Upload a User's Image / Topic Posts

In-Portal Forum

This is a place for users of In-Portal to ask questions, discuss various topics, and interact with other members of the In-Portal Community. Please report bugs through the Bugs Team (not the Forum). If you are interested in contributing or joining one of the many Teams for In-Portal, please check out the Contribute section of the website.
 

In-Portal Forum

Upload a User's Image (7)


Posted: 12/14/2005 12:10:08 AM

Reply Quoted  


I would like the user to be able to upload his or her image, just like they can upload an avatar.

I am trying to create a form to upload the image and add a new case to frontaction.php to handle the storing. This is where I am hung up of course.

I will be using the images to give my users a complete profile and it is working really good so far:

http://allpilots.com//index.php?env=-33:m20-1-1-1-s:l0-0-1-:n0-0-0:bb1-0-1-1-1-0-1&UserId=1


I uploaded the current picture through the admin panel


I am trying to copy the code used in the avatar case. Any ideas of what I need to change? I know this code will not work but I can't follow it well enough to modify it:

The new case in frontaction.php ---

case "m_userimage":

             if(is_array($_FILES))
             {
                foreach($_FILES as $field => $file)
                {
                   $allowed = TRUE;
                   if(strlen($_POST["imagetypes&quot[$field]))
                   {
                     $types = explode(",",strtolower($_POST["imagetypes&quot[$field]));
                     if(is_array($types))
                     {
                       if(count($types)>0)
                       {
                          $path_parts = pathinfo($file["name&quot);
                          $ext = $path_parts["extension"
                          $allowed = in_array($ext,$types);
                          if(!$allowed)
                          {
                            $MissingCount++;
                            $FormError["m_userimage&quot[$field] = "error one";
                          }
                        }
                     }
                   }
                   $maxsize = int)$_POST["maxsize&quot[$field];
                   if($maxsize>0 && $allowed && $file["size&quot>$maxsize)
                   {
                     $allowed = FALSE;
                     $MissingCount++;
                     $FormError["m_userimage&quot[$field] = "error two";
                   }
                }
             } else { $FormError["m_userimage&quot[$field] = "error three";
}

foreach($_FILES as $field => $file)
                   {
                     if($file["size&quot>0)
                     {
                       $imgname = $_POST["imagename&quot[$field];
                       $thumb = $_POST["isthumb&quot[$field];
                       $IsDefault = int)$_POST["imgdefault&quot[$field];
                       if($thumb)
                       {
                         $LocalThumb=1;
                       }
                       else
                         $LocalImage=1;
                       $img = $objImageList->GetImageByName($LinkResourceId,$imgname);
                       if(!is_object($img))
                       {
                         $img =& $objImageList->Add($imgname, "", $LinkResourceId,
                                                    $LocalImage, $LocalThumb,
                                                    "", "", 1, 0, $IsDefault, 0,0);
                       }
                       if($thumb)
                       {
                          $img->Set("LocalThumb",1);
                          $url = $img->StoreUploadedImage($file, 1,"kernel/images/",$thumb);
                          $img->Set("ThumbPath",$url);
                       }
                       else
                       {
                          $img->Set("LocalImage",1);
                          $url = $img->StoreUploadedImage($file, 1,"kernel/images/",$thumb);
                          $img->Set("LocalPath",$url);
                       }
                       $img->Update();
                     }
                   }
break;




[Edited By lhornaday on 12/14/05 12:10:56 AM]

Posted: 12/14/2005 10:56:43 AM

Reply Quoted  


Hello,

I think the best place to have that form would on user's profile (not registration). For form example look at themes/default/inbulletin/my_preferences/preferences_form.tpl. In regdards to case scenario in kernel/frontaction.php:

case "m_acctinfo":
//         phpinfo(INFO_VARIABLES);
        $_POST=inp_escape($_POST);
         $MissingCount = SetMissingDataErrors("m_acctinfo"
         $UserId = $_GET["UserId"
         if($UserId != $objSession->Get("PortalUserId&quot)
         {
             $MissingCount++;
             $FormError["m_acctinfo&quot["UserId&quot = language("lu_ferror_m_profile_userid"
         }
         if(strlen($_POST["password&quot)>0)
         {
           if(($_POST["password&quot != $_POST["passwordverify&quot) || !strlen($_POST["passwordverify&quot))
           {
             $MissingCount++;
             $FormError["m_acctinfo&quot["passwordverify&quot = language("lu_ferror_pswd_mismatch"
           }
         
             if(strlen($_POST["password&quot)>30)
             {
                // echo "VAR: ".$_POST["password" die();
                  $MissingCount++;
                 $FormError["m_acctinfo&quot["password&quot = language("lu_ferror_pswd_toolong"
             }
             
             if strlen($_POST['password']) < $objConfig->Get("Min_Password&quot)
             {
                  $MissingCount++;
                 $FormError["m_acctinfo&quot["password&quot = language("lu_ferror_pswd_tooshort"             
             }
         }
         
         $db =& GetADODBConnection();
         $email = GetVar('email');
         $test_id = $db->GetOne('SELECT PortalUserId FROM '.GetTablePrefix().'PortalUser WHERE Email = '.$db->qstr($email));
         if($test_id && $test_id != $objSession->Get('PortalUserId')) 
         {
             $MissingCount++;
            $FormError["m_acctinfo&quot["email&quot = language("lu_ferror_email_duplicate"             
         }
         
         
         if(!$MissingCount)
         {
             /* save profile */
             $u =& $objUsers->GetItem($UserId);
             $status = $u->Get("Status"
             $_POST["dob&quot = $_POST["dob_month&quot."/".$_POST["dob_day&quot."/".$_POST["dob_year"
             $dob = DateTimestamp($_POST["dob&quot, GetDateFormat());
             if(strlen($_POST["password&quot)>0)
             {
                 $password = md5($_POST["password&quot);
             }
             else
               $password = "";
             $objUsers->Edit_User($UserId, $_POST["username&quot, $password, $_POST["email&quot, 0, 
                                  $_POST["firstname&quot, $_POST["lastname&quot,  $status, $_POST["phone&quot
                                  $_POST["street&quot, $_POST["city&quot, $_POST["state&quot, $_POST["zip&quot
                                  $_POST["country&quot, $dob, $_POST['MinPwResetDelay']);

               $ResourceId= $u->Get("ResourceId"
               $objCustomDataList->LoadResource($ResourceId);
               $objCustomFields = new clsCustomFieldList(6);
               for($i=0;$i<$objCustomFields->NumItems(); $i++)
               {
                   $field = & $objCustomFields->GetItemRefByIndex($i);
                   $fieldid= $field->Get("CustomFieldId"
                   $fname = $field->Get("FieldName"
                   if(isset($_POST[$fname]))                   
                       $objCustomDataList->SetFieldValue($fieldid,$ResourceId,$_POST[$fname]);
                   elseif(isset($_POST[strtolower($fname)]))
                       $objCustomDataList->SetFieldValue($fieldid,$ResourceId,$_POST[strtolower($fname)]);
               }
               $objCustomDataList->SaveData(); 
                              
               // new part here !!!!!!!!!!               
                if(is_array($_FILES))
                {
                    foreach($_FILES as $field => $file)
                    {
                      if($file["size&quot>0)
                      {
                           $imgname = $_POST["imagename&quot[$field];
                           $u = $objUsers->GetItem($UserId);
                           
                           // get object of user image by image name
                           $img = $objImageList->GetImageByName($u->Get("ResourceId&quot, $imgname);
                           $IsDefault = int)$_POST["imgdefault&quot[$field];
                            
                           if(!is_object($img))
                           {
                                   $img =& $objImageList->Add($imgname, $imgname, $u->Get("ResourceId&quot,                                                 1, 1, "", "", 1, 0, $IsDefault, 0, 0);
                           }
                           
                           if $img->Get('Enabled')) 
                            {
                                $img->DeleteLocalImage();
                            
                                   $img->Set("LocalThumb",1);
                                   $url = $img->StoreUploadedImage($file, 1, "kernel/images/", 1);
                                   $img->Set("ThumbPath",$url);
            
                                   $img->Set("LocalImage",1);
                                   $file['tmp_name'] = $url;
                                   $url = $img->StoreUploadedImage($file, 1, "kernel/images/", 0, false);
                                   $img->Set("LocalPath",$url);
            
                                if($url)
                                    $img->Update();
                                else
                                    $img->Delete();
                            }
                            else
                            {
                                $FormError['m_acctinfo'][$imgname] = 'lu_profile_image_disabled';
                            }
                      }                  
                }
              }
               // END new part here !!!!!!!!!!               
         }
                  
         DeleteModuleTagCache('kernel');
     break;



Please backup everything before making any changes!

Thanks.


[Edited By Dmitry on 12/14/05 10:57:34 AM]

Posted: 12/14/2005 9:45:18 PM

Reply Quoted  


Thanks for the reply. I still have a problem with the upload, so I will submit a support ticket.

Posted: 12/30/2005 5:19:30 PM

Reply Quoted  


lhornaday wrote:12/14/2005 9:45:18 PM
Thanks for the reply. I still have a problem with the upload, so I will submit a support ticket.


Let me know if you still can't get this to work.

Thanks and Happy Holidays!

Posted: 12/30/2005 8:24:36 PM

Reply Quoted  


I didn't get help through the support ticket (#1532). Please let me know what it will take.

Posted: 01/02/2006 1:58:31 PM

Reply Quoted  


lhornaday wrote:12/30/2005 8:24:36 PM
I didn't get help through the support ticket (#1532). Please let me know what it will take.


Hello Luke,

Please accept my apologies, that ticket must been closed by some reason. I'll make sure to reopen it and get back to you on this.

Thanks.

Posted: 01/03/2006 5:31:46 PM

Reply Quoted  


THANK YOU

It is working great!