简体   繁体   English

我如何知道图像是否已完全传输?

[英]how can I know if an image has been completely transferred?

I'm sending a lot(a few per second) of images trough FTP to my web server. 我正在通过FTP将很多(每秒几张)图像通过FTP发送到我的Web服务器。 The problem is that I'm showing to the users the last image received, but sometimes the last image is not completely transferred. 问题是我向用户显示了收到的最后一张图像,但是有时最后一张图像没有完全传输。 So how can I check if the images is completely transferred, before showing it to the user. 因此,在向用户显示图像之前,如何检查图像是否已完全传输。

$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);
                }
            }
        }

The simple answer is to brute-force-open it in GD and see if you get an error. 简单的答案是在GD中强行打开它,看看是否出现错误。

The long (and preferable) answer is to upload a list of CRC32 checksums with your files, and have PHP check if the checksums match before displaying them. 长(也是更好的选择)的答案是上传带有文件的CRC32校验和列表,并让PHP在显示它们之前检查校验和是否匹配。

Had you provided code, I'd have provided implementation details, but... Lack of precision, lack of a precise answer. 如果您提供了代码,我将提供实现的详细信息,但是...缺乏精确度,缺乏精确的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM