View Single Post
Old 05-24-2002, 09:09 AM  
s9ann0
Confirmed User
 
Join Date: Sep 2001
Location: Boston
Posts: 4,873
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
s9ann0 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote