function getUrlImg2($url,$filename=""){
if(!createDirs(dirname($filename))){
die('无法创建文件夹');
}
if(!$url)
die('无url');
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
if($size){
$fp2=@fopen($filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}else
return false;
}
function getUrlImg3($url,$filename=""){
if(!createDirs(dirname($filename))){
die('无法创建文件夹');
}
if(!$url)
die('无url');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0); //只取body头
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$package = curl_exec($ch);
$httpinfo = curl_getinfo($ch);
curl_close($ch);
$imageAll = array_merge(array('header' => $httpinfo), array('body' => $package));
//上半部是下载,下半部是保存
if($package){
$local_file = fopen($filename, 'w');
if (false !== $local_file){
if (false !== fwrite($local_file, $package)){
fclose($local_file);
return true;
}
}
}
return false;
}
上面两个方法在本地测试都是可以的,但是放到服务器上,下载回来的图片都只有100多字节,图片还打不开。这个方法是用在向微信服务器获取图片用的,请问是不是php.ini里的相关设置造成的?改哪些设置可以弄好?
人生最曼妙的风景,竟是内心的淡定与从容!