<?PHP/** * test.php:*/Header(' Content-type:text/html;charset=utf8 ');$ch=curl_init ();//Add @ Sign Curl will take it as a file upload process$data=Array(' img ' = ' @ '.dirname(__file__).‘ /img/1.jpg '); curl_setopt ($ch, Curlopt_url, "http://localhost:8088/curl/get_img.php"); curl_setopt ($ch, Curlopt_returntransfer,true); curl_setopt ($ch, Curlopt_post,true); curl_setopt ($ch, Curlopt_postfields,$data);$result= Curl_exec ($ch); Curl_close ($ch);EchoJson_decode ($result);? ><?PHP/** * get_img.php:*/if($_files){ $filename=$_files[' IMG '] [' Name ']; $tmpname=$_files[' IMG '] [' Tmp_name ']; if(Move_uploaded_file($tmpname,dirname(__file__).‘ /upload/'.$filename)){ EchoJson_encode (' Upload successful '); }Else{ $data= Json_encode ($_files); Echo $data; }}?>when I visit TestThe "Upload succeeded" will be displayed in PHP and a 1.jpg image file will be generated under the Upload folder.
PHP Curl uploads files to remote server