方法一:
foreach ($images as $Imgkey => $Imgval){
$i++;
$parse_url = parse_url($Imgval->url);
$pathinfo = pathinfo($parse_url['path']);
if(isset($pathinfo['basename']) && $pathinfo['basename'] == 'spaceball.gif'){
continue;
}
if (!isset($pathinfo['extension'])) {
$filename = $pathinfo['filename'] . '.jpg';
} else {
$filename = $pathinfo['basename'];
}
$localpath =public_path( '/pddGoodsImg/' . $v->excel_goods_name );
if (!file_exists($localpath)) {
mkdir($localpath, 0777, true);
}
$localpath = '/pddGoodsImg/' . $v->excel_goods_name . '/'.$i.'_'.$filename;
// $img = file_get_contents("compress.zlib://". $Imgval->url);
// file_put_contents(public_path($localpath), $img);
$fp = fopen(public_path($localpath), 'w+');
$headers = array('content-type: image/your_image_type');
$ch = curl_init($Imgval->url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_ENCODING,'gzip');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)');
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
方法二:
$img = file_get_contents("compress.zlib://". $Imgval->url);
file_put_contents(public_path($localpath), $img);
感谢观看,希望帮到您,如果有其他问题可以给我评论,我看到会第一时间回复。