我通过 FTP 向我的网络服务器发送了很多(每秒几个)图像。问题是我向用户显示收到的最后一张图片,但有时最后一张图片没有完全传输。那么如何在向用户显示图像之前检查图像是否已完全传输。
$directory = dir($path);
while (false !== ($entry = $directory->read())) {
$filepath = "{$path}/{$entry}";
// could do also other checks than just checking whether the entry is a file
$imageFormats = array(IMAGETYPE_JPEG);
if (is_file($filepath) && filectime($filepath) > $latest_ctime)
{
if(in_array(exif_imagetype($filepath), $imageFormats) && $imageResource = imagecreatefromjpeg($filepath))
{
$latest_filename = $entry;
$latest_ctime = filectime($filepath);
}
}
}