Jürgen Paul
Jürgen Paul

Reputation: 15007

Sending data to a remote form

Let's say I have a form from a remote area http://example.com/form.php which contains:

<form action="" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file" /> 
  <input type="text" name="name">
  <input type="text" name="age">
  <input type="text" name="sex">
  <br />
  <input type="submit" name="submit" value="Submit" />
</form>

How do I send data to that form, submit it and fetch whatever the result of the form submission is? I found a function in the php site but I don't know how to use it or if it's the right one to use.

http://www.php.net/manual/en/function.stream-context-create.php#90411

Upvotes: 0

Views: 1011

Answers (1)

Brad
Brad

Reputation: 163234

You want to POST to that form programmatically? You can do this easily with cURL.

$data['name'] = 'Something';
$data['age'] = 'Something Else';
$data['file'] = "@/somepath/somefile";

$ch = curl_init('http://example.com/form.php');
curl_setopt($ch, 'CURLOPT_POST', true);
curl_setopt($ch, 'CURLOPT_POSTFIELDS', $data);

Upvotes: 3

Related Questions