PHP POST

function post($url,$post_string)
	{
	     $ch=curl_init();
	curl_setopt_array($ch, array(CURLOPT_URL=>$url,CURLOPT_SSL_VERIFYPEER=>0,CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>$post_string));
	$result=curl_exec($ch);
	curl_close($ch);
	return $result;
	}

function uploadByCURL($url,$post_data)
{
	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_POST, 1 );
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$result = curl_exec($curl);
	$error = curl_error($curl);
	return $error ? $error : $result;
}

$url = "http://127.0.0.1/tietuku//demo//list.php";
$data = array(
"username" => $username,
"password"  => $password,
"file1"  => "@".realpath("1.jpg")
);
var_dump($data);
print_r(uploadByCURL($url,$data));


你可能感兴趣的:(PHP POST)