|
here is the code I wrote, put this in a script and run it at upload time it checks for correct start of GIF file and correct header and footer of a JPEG
it uses sysread to be more efficient instead of usual perl file shit
# example - $pathfile = "/path/to/uploaded/file.gif";
if ($pathfile =~ /.gif$/gi)
{
open (TEST,"<$pathfile");
sysread (TEST,$check_header,4);
close (TEST);
$header = "GIF8";
unlink ("$pathfile") if ($check_header ne "$header");
}
elsif ($pathfile =~ /.jpg$/gi)
{
open (TEST,"<$pathfile");
sysread (TEST,$check_header,4);
sysseek (TEST,-2,2);
sysread (TEST,$check_footer,2);
close (TEST);
$header = "ÿØÿà";
$footer = "ÿÙ";
unlink ("$pathfile") if ($check_header ne "$header");
unlink ("$pathfile") if ($check_footer ne "$footer");
}
don't diss da jungle
|