1. Get the remote picture
/**
$Path to save the address of the picture
$url the remote picture address to get
**/
function getimg ($path, $url) {
$aext=Explode‘.‘,$url);
$ext= End ($aext);
$name = $path.' /'. Time () . '. ' . $ext;
$source=file_get_contents ($url);
File_put_contents ($name,$source);
return $name;
}
2. Uploading images
/**
$posturl the address of the uploaded image
$path the address where the local picture is located
**/
function Postimg ($posturl, $path) {
$obj= new curlfile ($path);
$obj-Setmimetype ("Application/octet-stream");The file type must be specified, otherwise default to Application/octet-stream, binary stream file </span>
$post [' Filedata ']=$obj;
$ch=Curl_init ();
curl_setopt ($ch,Curlopt_header,FALSE);
When enabled, a regular post request is sent with the type: application/x-www-form-urlencoded, just as the form was submitted.
curl_setopt ($ch,Curlopt_post,true);
curl_setopt ($ch,Curlopt_returntransfer,true);
curl_setopt ( $ch, curlopt_binarytransfer, true);
curl_setopt ( $ch, Curlopt_postfields, $post);
curl_setopt ( $ch, Curlopt_url, $posturl); //upload class
Span style= "COLOR: #7587a6" > $info = curl_exec ( $ch);
curl_close ( $ch);
return $info;
}
PHP get remote picture simulation Post,file upload to specified server