Hello!

There is a script that copies the image using the http protocol. Copying is done by the copy function.

Faced with the fact that from time to time the image is copied, but not completely. Not completely - this means that, for example, if you look at the copied image in the browser, it will be shown in half.

I tried to check the image for validity through getimagesize , but this feature shows that everything is in order. That is, the file header is fine.

It seems that the remote server sometimes just breaks the connection, so the first part of the file is correct, with all the headers, and then the file stops unexpectedly.

We correspond with the administrator of the remote server, but so far to no avail, he claims that the server gives the file completely, without errors.

But in fact the images are saved incorrectly.

How can PCP check that the file is copied completely, without errors? What file is a valid image?

The source file is 100% correct, it can be seen in the same browser, if you look at the source file.

The difficulty is that it happens regularly, but rarely. When I check the script with my eyes, out of about 30 runs, the image loaded incorrectly once. That is, debugging capabilities are very limited, unfortunately.

And there are several tens of thousands of files, some of which are incorrect. How to find them?

Thank.

  • check the result of the function? If 30 times to open the original image from a remote server in the browser (without caching), is it always correct? - teran
  • Compare what's in Content-Length and reality after downloading. Do not match - restart. - user207618
  • In advanced cases, use something like crc32 . - user207618

1 answer 1

I found out that the correctness of the image can be checked through imagecopyresampled. If false, then something is wrong with the image.

Thank.

  • But checking the content-length or crc32 is much more adequate things - andreymal
  • And how exactly can you check? I understand that crc32 gives the checksum of the file - with what should it be compared? - user2989927 February
  • Ask crc32 from the one who gives you the image and compare it with yours :) If nobody wants to give crc32, then at least the content-length should always be - andreymal