1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| $upload_url = 'http://192.168.0.99:5000/upload';
$image_file = './test.jpg';
$value = explode(".", $image_file); $extension = strtolower(array_pop($value));
$dir = 'aurthur'; $save_path = 'uploads/'.$dir.'/'.date('Y').'/'.date('md').'/'; $save_rule = md5(uniqid(mt_rand(), true)); if(!is_dir($save_path)){ if(false === mkdir($save_path, 0700, true)){ exit('创建文件夹失败'); } } $save_image_file = $save_path.$save_rule.".$extension";
file_put_contents($save_image_file, file_get_contents($image_file));
$realpath = realpath($save_image_file);
$ch = curl_init();
$post_data = file_get_contents($realpath);
$headers = array();
$headers[] = 'Content-Type:'.$extension;
curl_setopt($ch, CURLOPT_URL, $upload_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$info = curl_exec($ch); curl_close($ch);
$json = json_decode($info, true); echo= $json['info'];
|