Reputation: 3780
I'm sending a lot(a few per second) of images trough FTP to my web server. 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);
}
}
}
Upvotes: 0
Views: 95
Reputation: 19662
The simple answer is to brute-force-open it in GD and see if you get an error.
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.
Had you provided code, I'd have provided implementation details, but... Lack of precision, lack of a precise answer.
Upvotes: 9