0

I have a form with a few text fields and and a file upload field.

<form enctype="multipart/form-data" method="POST">
<input name="source" type="file">
<input name="message" type="text" value="">
</form>

I need to post the text inputs and file inputs to itself. Then take the posted data, and post it to facebook's graph api using curl.

Is this possible? If so, any code examples for sending file data over curl would be appreciated. Thanks!

Fostah
  • 2,947
  • 4
  • 56
  • 78
  • 1
    I would combine the general concepts of [Variables From External Sources](http://php.net/manual/en/language.variables.external.php) and [Handling file uploads](http://php.net/manual/en/features.file-upload.php) with the answer given in [How to upload a file with PHP, curl and HTTP POST by streaming the file?](http://stackoverflow.com/questions/5260985/how-to-upload-a-file-with-php-curl-and-http-post-by-streaming-the-file). – hakre Aug 09 '11 at 00:15

1 Answers1

0

Figured it out. Here is the solution:

$graph_url = "https://graph.facebook.com/". $album_id
    . "/photos?access_token=" . $_POST['accesstoken'];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, $graph_url);
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="source">
    $post = array(
        "source"=>"@".$_FILES['source']['tmp_name'],
            "message"=>$_POST['meessage']
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch);
}
?>
Fostah
  • 2,947
  • 4
  • 56
  • 78