时间:2021-07-01 10:21:17 帮助过:4人阅读
$psn_id = "1fbahh";
$url = SERVER_URL . '/get_imginfo.php';
//SERVER_URL为我自己定义的常量,其值为:http://localhost:8080/phpClientSer
$ans = postData_json($url, "psn_id=$psn_id");//postData_json()和postData()在check.php
print_r($ans);
if ($ans['count'] > 0) {
if (!file_exists("org")) {
mkdir("org");
mkdir("org/resouse/"); //从服务器读取过来的原图片存放路径
mkdir("org/w100/"); //把上目录中临时存放的图片处理为宽度100后存放的路径
mkdir("org/temp/"); //出来gif图片是的临时mul
}
foreach ($ans['pdt_id'] as $k => $pdt_id) {
$img = "org/resouse/" . $pdt_id . $ans['img_style'][$k];
$url = SERVER_URL . '/get_stream.php';//访问服务器的路径
$postString = $ans['img_url'][$k]; //传递的参数[服务器上图片的路径]
$stream = postData($url, "img_url=" . $ans['img_url'][$k]);//从服务器读取的图片内容
$file = fopen($img, "w+"); //打开文件准备写入
fwrite($file, $stream); //写入
fclose($file); //关闭
$image_resize = new image_resize();
$image_resize->act($img, $pdt_id);//处理图片
$img_u = "org/w100/" . $pdt_id . $ans['img_style'][$k];//处理后图片的存放路径
//下面的代码是把处理过的图片转为二进制传到服务器,问题就出在这段代码
$stm = file_get_contents($img_u);
$url = SERVER_URL . '/create_img.php';
$postString = "pdt_id=$pdt_id&img_style=" . $ans['img_style'][$k] . "&img_stm=" . $stm;
$move = postData($url, $postString);
echo "result---------" . $move . "\r\n";
}
}
?>
function postData($remote_server, $post_string) {
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded' .
'\r\n' . 'User-Agent : Jimmy\'s POST Example beta' .
'\r\n' . 'Content-length:' . strlen($post_string) + 8,
'content' => $post_string)
);
$stream_context = stream_context_create($context);
$data = file_get_contents($remote_server, false, $stream_context);
return $data;
}
function postData_json($remote_server, $post_string) {
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded' .
'\r\n' . 'User-Agent : Jimmy\'s POST Example beta' .
'\r\n' . 'Content-length:' . strlen($post_string) + 8,
'content' => $post_string)
);
$stream_context = stream_context_create($context);
$data = file_get_contents($remote_server, false, $stream_context);
return json_decode($data, true);