Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created July 2, 2012 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cam-gists/3035265 to your computer and use it in GitHub Desktop.
Save cam-gists/3035265 to your computer and use it in GitHub Desktop.
PHP: file_get_contents vs. cURL
<?php
$html = file_get_contents("http://example.com/product/42");
$context = stream_context_create(array(
"http" => array(
"method" => "POST",
"header" => "Content-Type: multipart/form-data; boundary=--foo\r\n",
"content" => "--foo\r\n"
. "Content-Disposition: form-data; name=\"myFile\"; filename=\"image.jpg\"\r\n"
. "Content-Type: image/jpeg\r\n\r\n"
. file_get_contents("image.jpg") . "\r\n"
. "--foo--"
)
));
$html = file_get_contents("http://example.com/upload.php", false, $context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment