JPEG image should start with 0xFFD8 and end with 0xFFD9
Code: Select all
// this may help to fix the error
//check for jpeg file header and footer - also try to fix it
function check_jpeg($f, $fix=false )
{
if ( false !== (@$fd = fopen($f, 'r+b' )) ){
if ( fread($fd,2)==chr(255).chr(216) ){
fseek ( $fd, -2, SEEK_END );
if ( fread($fd,2)==chr(255).chr(217) ){
fclose($fd);
return true;
}else{
if ( $fix && fwrite($fd,chr(255).chr(217)) ){return true;}
fclose($fd);
return false;
}
}else{fclose($fd); return false;}
}else{
return false;
}
}