test.php:
<?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);
echo Json_decode ($result);
?>
get_img.php:
<?php
if ($_files) {
$filename = $_files[' img ' [' name '];
$tmpname = $_files[' img ' [' tmp_name '];
if (Move_uploaded_file ($tmpname, DirName (__file__). ' /upload/'. $filename)) {
echo Json_encode (' upload successful ');
}else{
$data = Json_encode ($_files);
Echo $data;
}
}
?>
When I visit test.php, "Upload succeeded" will be displayed, and a 1.jpg picture file will be generated under the Upload folder. Simulate PHP curl uploading files to a remote server
Simulate PHP curl uploading files to a remote server