This article describes the method of saving any network pictures to the server in php. Share it with everyone for your reference. The specific analysis is as follows:
Specify any network image address and download it to the local server through this function
<?php function saveImage($path) { if(!preg_match('/\/([^\/]+\.[a-z]{3,4})$/i',$path,$matches)) die('Use image please'); $image_name = strToLower($matches[1]); $ch = curl_init ($path); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $img = curl_exec ($ch); curl_close ($ch); $fp = fopen($image_name,'w'); fwrite($fp, $img); fclose($fp); } saveImage('http://www.bkjia.com/images/logo.jpg'); ?>
I hope this article will be helpful to everyone’s PHP programming design.