Answers.Body: <p>The image data is not going to be in POST variable. You should be using</p>
  
  <pre><code>$userPhoto = UploadedFile::getInstanceByName('userPhoto');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T19:56:59.113Z
Answers.Text: ahh getting closer.  how do i make that an \craft\image?  getting this error Argument 2 passed to Craft\UsersService::saveUserPhoto() must be an instance of Craft\Image, instance of CUploadedFile given
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T20:42:50.193Z
Answers.Text: Take a look at UsersController::_processUserPhoto(). All the cropping logic there just ensures that the image is square.
Answers.UserDisplayName: Andris Sevcenko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T22:13:08.857Z
Answers.Text: hmm how would i call that from a plugin controller?  Fatal error: Call to private method Craft\UsersController::_processUserPhoto() from context 'Craft\SalesforceController'   I tried just $userPhoto = UploadedFile::getInstanceByName('photo');;
      $userPhoto = UsersController::_processUserPhoto($userPhoto);
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T22:15:38.510Z
Answers.Text: ahh nevermind i see it in there.. do user profile images have to be square?
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-08T09:59:52.823Z
Answers.Text: Well, that's how they are in the CP. If you don't mind them being stretched or squeezed in the CP, you'll be fine.
Answers.UserDisplayName: Andris Sevcenko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-06T07:39:58.097Z
Answers.LastActivityDate: 2015-03-06T07:39:58.097Z
Answers.UserDisplayName: Andris Sevcenko
Body: <p>Im trying to upload a profile image from a front end form via a controller function</p>
  
  <p>this is what i have but the $image keeps returning null?</p>
  
  <pre><code>&lt;form name="updateProfile" method="post" enctype="multipart/form-data"&gt;
       &lt;input type="hidden" name="action" value="salesforce/saveContact"&gt;
       &lt;input type="file" name="photo" id="avatarUpload"&gt;
       &lt;input type="submit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and my controller action is</p>
  
  <pre><code>public function actionSaveContact()
  {
  
      $this-&gt;requirePostRequest();
  
      $userPhoto = craft()-&gt;request-&gt;getPost('photo');
  
      $user = craft()-&gt;userSession-&gt;getUser();
  
      craft()-&gt;users-&gt;saveUserPhoto('test.jpg',$userPhoto, $user);
  
  }
  </code></pre>
  
  <p>Not sure what im doing wrong?</p>
  
Tags: <form><image>
Title: Upload user profile image from custom plugin controller
ThreadText: # Upload user profile image from custom plugin controller
  
  (Asked by: username_0 on 2015-03-06)
  
  Im trying to upload a profile image from a front end form via a controller function
  
  this is what i have but the $image keeps returning null?
  
  ```
  <form name="updateProfile" method="post" enctype="multipart/form-data">
       <input type="hidden" name="action" value="salesforce/saveContact">
       <input type="file" name="photo" id="avatarUpload">
       <input type="submit"/>
  </form>
  
  ```
  
  and my controller action is
  
  ```
  public function actionSaveContact()
  {
  
      $this->requirePostRequest();
  
      $userPhoto = craft()->request->getPost('photo');
  
      $user = craft()->userSession->getUser();
  
      craft()->users->saveUserPhoto('test.jpg',$userPhoto, $user);
  
  }
  
  ```
  
  Not sure what im doing wrong?
  
  **Tags:** form, image
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-06. Score: 2 | Accepted answer
  
  The image data is not going to be in POST variable. You should be using
  
  ```
  $userPhoto = UploadedFile::getInstanceByName('userPhoto');
  
  ```
  
  > **Comments:**
  > **username_0**: ahh getting closer.  how do i make that an \craft\image?  getting this error Argument 2 passed to Craft\UsersService::saveUserPhoto() must be an instance of Craft\Image, instance of CUploadedFile given  
  > **username_1**: Take a look at UsersController::_processUserPhoto(). All the cropping logic there just ensures that the image is square.  
  > **username_0**: hmm how would i call that from a plugin controller?  Fatal error: Call to private method Craft\UsersController::_processUserPhoto() from context 'Craft\SalesforceController'   I tried just $userPhoto = UploadedFile::getInstanceByName('photo');;     $userPhoto = UsersController::_processUserPhoto($userPhoto);  
  > **username_0**: ahh nevermind i see it in there.. do user profile images have to be square?  
  > **username_1**: Well, that's how they are in the CP. If you don't mind them being stretched or squeezed in the CP, you'll be fine.  
  
  ---
  
  