Sometimes php hung during ImageCreateFrom jpeg when it convert wrong
picture (jpg file with errors). I found the function which check jpg
file. But I don't know how to use that function. I just want to have
the information that file is ok or file is corrupt (for example $jpg =
ok - I've got good file, $jpg = wrong - I've got file with errors). I
include that function below. Really thaks for help!
function check_jpeg($f, $fix=false ){
# [070203]
# check for jpeg file header and footer - also try to fix it
if ( false !== (@$fd = fopen($f, 'r+b' )) ){
if ( fread($fd,2)==c hr(255).chr(216 ) ){
fseek ( $fd, -2, SEEK_END );
if ( fread($fd,2)==c hr(255).chr(217 ) ){
fclose($fd);
return true;
}else{
if ( $fix && fwrite($fd,chr( 255).chr(217)) ){return true;}
fclose($fd);
return false;
}
}else{fclose($f d); return false;}
}else{
return false;
}
}
picture (jpg file with errors). I found the function which check jpg
file. But I don't know how to use that function. I just want to have
the information that file is ok or file is corrupt (for example $jpg =
ok - I've got good file, $jpg = wrong - I've got file with errors). I
include that function below. Really thaks for help!
function check_jpeg($f, $fix=false ){
# [070203]
# check for jpeg file header and footer - also try to fix it
if ( false !== (@$fd = fopen($f, 'r+b' )) ){
if ( fread($fd,2)==c hr(255).chr(216 ) ){
fseek ( $fd, -2, SEEK_END );
if ( fread($fd,2)==c hr(255).chr(217 ) ){
fclose($fd);
return true;
}else{
if ( $fix && fwrite($fd,chr( 255).chr(217)) ){return true;}
fclose($fd);
return false;
}
}else{fclose($f d); return false;}
}else{
return false;
}
}
Comment