【发布时间】:2010-07-08 10:51:09
【问题描述】:
更新:我已经简化了代码(尝试)
我正在尝试以数组的形式下载一系列图像,但显然有些不对:
function savePhoto($remoteImage,$fname) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_NOBODY, true);
curl_setopt ($ch, CURLOPT_URL, $remoteImage);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$fileContents = curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($retcode==200) {
$newImg = imagecreatefromstring($fileContents);
imagejpeg($newImg, ".{$fname}.jpg",100);
}
return $retcode;
}
$filesToGet = array('009');
$filesToPrint = array();
foreach ($filesToGet as $file) {
if(savePhoto('http://pimpin.dk/jpeg/'.$file.'.jpg',$file)==200) {
$size = getimagesize(".".$file.".jpg");
echo $size[0] . " * " . $size[1] . "<br />";
}
}
我收到以下错误:
警告:imagecreatefromstring() [function.imagecreatefromstring]: 中的空字符串或无效图像 C:\inetpub\vhosts\dehold.net\httpdocs\ripdw\index.php 在第 15 行
警告:imagejpeg():已提供 参数不是有效的图像资源 在 C:\inetpub\vhosts\dehold.net\httpdocs\ripdw\index.php 第 16 行
警告:getimagesize(.009.jpg) [function.getimagesize]:未能 打开流:没有这样的文件或目录 在 C:\inetpub\vhosts\dehold.net\httpdocs\ripdw\index.php 在第 26 行 *
【问题讨论】:
-
大家好!我已经更新了问题:-)这是我在堆栈上的第一个 Q,所以我希望你能忍受我:)
标签: arrays curl php getimagesize