title: Facebook api php sdk 4.0 - uploading photo to facebook using "new curlfile"
body: <p>I am trying to upload a photo that I have saved on my server onto my facebook via this facebook application. </p>
  
  <p>My facebook request originally was:</p>
  
  <pre><code>$response = (new FacebookRequest(
      $session,
      'POST',
      '/me/photos',
      array(
          'source' =&gt;  '@' . $_FILES['file']['tmp_name'] ,
      )
  ))-&gt;execute()-&gt;getGraphObject()-&gt;asArray();
  
  /* handle the result */
  print_r($response);
  </code></pre>
  
  <p>But apparently the syntax has changed now and I need to have something like this instead: </p>
  
  <pre><code>'source'=&gt; new CURLFile(' '),
  </code></pre>
  
  <p>Not sure what to put as the parameters because my image is stored in a folder in my server.<br>
  My application allows the user to browse and submit a photo from their computer. This will be saved onto the server before it's posted onto facebook. I used the multiform/part:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data"&gt;
      Please select a photo to upload &lt;input type="file" name="file" id="file"&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="submit" value="Upload" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and the code I have to upload the photo to the server is as follows:</p>
  
  <pre><code>if(isset($_POST['submit'])) {
      $file_type = $_FILES['file']['type']; //returns the file type
      $allowed = array("image/jpeg", "image/gif", "image/png", "image/jpg"); //specifies allowed file types
      if(!in_array($file_type, $allowed)) {
          $error_message = 'Only jpeg, jpg, gif, and png files are allowed. &lt;br&gt; 
          Please click back and try again.';
          echo $error_message;
          exit();
      }
  
  $name = $_FILES['file']['name'];  //original path of the uploaded file
  $temp_name = $_FILES['file']['tmp_name'];  //contains the path to the temporary file that resides on the server
  
  if(isset($name)) {
      if(!empty($name)) {      
          $location = 'uploads/'; //save photo to the folder: uploads
          if(move_uploaded_file($temp_name, $location.$name)){
              echo 'Photo was successfully uploaded.';
          }
      }       
  } 
  else {
      echo 'Photo was unsuccessfully uploaded, click back and try again.';
  }
  </code></pre>
  
  <p>I know the session works because I was able to POST a message onto facebook.</p>