Created
December 6, 2012 07:26
-
-
Save outman/4222488 to your computer and use it in GitHub Desktop.
upload file to server by curl post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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