问题
使用 PHP 在图像更改前后使用相同的 URL 下载远程图像,即使来源不同,也会下载相同的照片。某处图像被缓存。
问题不在于浏览器缓存,因为我在通过 FTP 复制后直接通过 Windows 资源管理器查看照片。
例子
下午 1:00:下载照片 URL A -> 下载照片 A
下午 1:30:照片 A 更改为照片 B,但照片 URL 保持不变
2:00 pm:再次下载照片 URL A -> 下载照片 A(但应该是照片 B)
我的下载脚本
function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile )
{
$fw = $forcedwidth;
$fh = $forcedheight;
$is = getimagesize( $sourcefile );
if( $is[0] >= $is[1] )
{
$orientation = 0;
}
else
{
$orientation = 1;
$fw = $forcedheight;
$fh = $forcedwidth;
}
if ( $is[0] > $fw || $is[1] > $fh )
{
if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) )
{
$iw = $fw;
$ih = ( $fw / $is[0] ) * $is[1];
}
else
{
$ih = $fh;
$iw = ( $ih / $is[1] ) * $is[0];
}
$t = 1;
}
else
{
$iw = $is[0];
$ih = $is[1];
$t = 2;
}
if ( $t == 1 )
{
$img_src = imagecreatefromjpeg( $sourcefile );
$img_dst = imagecreatetruecolor( $iw, $ih );
imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );
if( !imagejpeg( $img_dst, $destfile, 95 ) )
{
exit( );
}
return true;
}
else if ( $t == 2 )
{
copy( $sourcefile, $destfile );
return true;
}
}