In a reply to the question check manually for jpeg end of file marker ffd9 (?) in php to catch truncation errors the EOF chars for a jpg are shown as "\xFF\xD9". When I use this the script traps what appear to be valid jpgs, whereas if I remove the 'x' characters it allows them. What is the purpose of the x's and does it matter if they are omitted?
$imgdata = fopen($uploadfile, 'r'); // 'r' is for reading
fseek($imgdata, -2, SEEK_END); // move to EOF -2
$eofdata = fread($imgdata, 2);
fclose($imgdata);
switch ($mimetype) {
case "image/jpeg":
$eof = "\xFF\xD9";
break;
case "image/pjpeg":
$eof = "\xFF\xD9";
break;
case "image/png":
$eof = "\60\82";
break;
}
if ($eofdata != $eof) {
$valid = false;
}