Skip to content

Instantly share code, notes, and snippets.

@outman
Created December 6, 2012 07:26
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 outman/4222488 to your computer and use it in GitHub Desktop.
Save outman/4222488 to your computer and use it in GitHub Desktop.
upload file to server by curl post
Client
<?php
class HTTPClient {
function __construct($url, $port = 80)
{
$this->url = $url;
$this->port = $port;
}
function postTo()
{
$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_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeader);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_PORT, $this->port);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'Filedata' => '@E:/log.txt',
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
$url = "http://678bt.com";
$client = new HTTPClient($url);
$resp = $client->postTo();
echo $resp;
?>
SERVER:
<?php
if ($_POST) {
file_put_contents("./log.txt", serialize($_FILES));
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./test.txt");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment