Uploading files on the client is a scenario often encountered in web development. No further details will be given here. What we want to elaborate here is how to upload files to other servers on the server side.
This scenario is often encountered when resources of multiple servers need to be synchronized, such as uploading images uploaded by users from one server
to other servers.
In fact, uploading files on the server side is not a difficult task. You can just use PHP's curl_init().
'@'.$img_path);//文件路径,前面要加@,表明是文件上传. foreach($hosts as $host) { $curl = curl_init(); //处理上传图片的URL,与客户端上传到服务器的原理是一样的 curl_setopt($curl,CURLOPT_URL,'http://'.$host.'/upload.php'); curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl,CURLOPT_POSTFIELDS,$file); curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,CURLOPT_HEADER,0); curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, FALSE); $result = curl_exec($curl); //$result 获取页面信息 curl_close($curl); } ?>