title: Facebook: php upload photo and post on wall
body: <p>new to php please forgive my silly questions.</p>
  
  <p>I am creating my first fb app. It allows user to browse through their local drive and select a photo. Once it is submit, it will redirect to the next page and process to the storing onto my server first then posting to user's wall.</p>
  
  <p>The application is not working really that much. The part where user browse and app storing the photo on to my server is working, but it fails to grab the photo back from my server and post it on the user's wall.</p>
  
  <p>config.php:</p>
  
  <pre><code> &lt;?php
  require_once 'facebook.php';
  
  $app_id = "";
  $app_key = "";
  $app_secret = "";
  $canvas_url = "";
  
  $facebook = new Facebook(array(
  'appId'  =&gt; $app_id,
  'secret' =&gt; $app_secret,
  'cookie' =&gt; true
  ));
  
  $session = $facebook-&gt;getSession();
  
  if (!$session) {
  
          $url = $facebook-&gt;getLoginUrl(array(
          'canvas' =&gt; 1,
          'fbconnect' =&gt; 0,
          'req_perms' =&gt; 'publish_stream, user_photos, read_stream, read_friendlists'
          ));
  
          echo "&lt;script type='text/javascript'&gt;top.location.href = '$url';&lt;/script&gt;";
  
      }//end if session user 
  else
  {
  
          try {
  
          $uid = $facebook-&gt;getUser();
          $me = $facebook-&gt;api('/me');
  
          $updated = date("l, F j, Y", strtotime($me['updated_time']));
  
          echo "Hello " . $me['name'] . "&lt;br /&gt;";
          echo "You last updated your profile on " . $updated  . "&lt;br /&gt;" ;
          echo "&lt;img src='https://graph.facebook.com/".$uid."/picture'/&gt;"; 
          }//end try getUser 
          catch (FacebookApiException $e) {
  
          echo "Error:" . print_r($e, true);
  
          }//end catch getUser 
  }//end else user
  </code></pre>
  
  <p>index.php contains the form:</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="uploader.php" method="POST"&gt;
  &lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000" /&gt;
  Choose a file to upload: &lt;input name="uploadedfile" type="file" /&gt;&lt;br /&gt;
  &lt;input type="submit" value="Upload File" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>uploader.php run the process</p>
  
  <pre><code>$target_path = "uploads/";
          $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
  
          if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
              echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
              " has been uploaded" . "&lt;br /&gt;";
          } else{
              echo "There was an error uploading the file, please try again!" . "&lt;br /&gt;";
          }
          try {
      $post_id = $facebook-&gt;api("/".$uid."/feed", "post", array("picture"=&gt;$target_path));
      if(isset($post_id))
          echo "A new post to your wall has been posted with id: $post_id";
    } catch (FacebookApiException $e) {
      error_log($e);
    }
  </code></pre>
  
  <p>I have been trying many different ways which i could find online but it does not work. i have tried adding $facebook->setFileUploadSupport(true); but receive errors.</p>
  
  <p>Please advice me how i could go about getting to upload the photo onto the user wall.
  Thank you very much</p>