初学 代码有点乱 把地址给去掉了
<?php
set_time_limit(0);
$curl = "https://www.xxx.com/1.htm";
$file = file_get_contents($curl);
$reg = '/\/htm\/(.*?)\.htm/';
preg_match_all($reg,$file,$array);
// echo '
';
$array_url = $array[0];
// print_r($array);
$leng = count($array_url);echo "all:".$leng."\r\n";//输出总连接数 for ($c=0;$c<=$leng;$c++){
// echo $array[$c];
$url='https://www.xxx.com'.$array_url[$c]; if ($filepic=file_get_contents($url)){ echo "open:".$url."(ok) \r\n"; }else{ echo "open:".$url."(error) \r\n"; continue; } //echo $filepic; $preg = '/https\:\/\/pic\.(.*?)\.(jpg|png)/'; preg_match_all($preg,$filepic,$arr); $arr_pic = $arr[0];
// print_r($arr);
$num = count($arr_pic);echo "url:".$url."number_size_pic".$num. "\r\n"; date_default_timezone_set('Asia/Shanghai'); $path='images/'.date('ymdHis').rand(10,99).'/'; if (!file_exists($path)){ if (mkdir($path)){ echo "open:".$path."ok \r\n"; }else{ echo "open:".$path."error \r\n"; } } for($i=0;$i<=$num;$i++){ $pic=$arr_pic[$i]; $picname = rand(100,999).'.jpg'; if (copy($pic,"./$path.$picname")){ echo "pic_down_rigth:$path.$picname \r\n"; }else{ echo "pic_down_error:".$pic."\r\n"; continue; } } fclose($filepic); } 上面代码我在浏览器 localhost.com/test.php 可以运行正常能抓取图片保存下来,但是我在cmd下运行就不行了 ![图片说明](https://img-ask.csdn.net/upload/201708/04/1501826512_26125.jpg)