Image security in redactorjs editor

141 Views Asked by At

There is a security settings which perform a check if it actually is a picture, When a user uploads a picture.

function is_image($image_path)
{
if (!$f = fopen($image_path, 'rb'))
{
    return false;
}

$data = fread($f, 8);
fclose($f);

// signature checking
$unpacked = unpack("H12", $data);
if (array_pop($unpacked) == '474946383961' || array_pop($unpacked) == '474946383761')     return "gif";
$unpacked = unpack("H4", $data);
if (array_pop($unpacked) == 'ffd8') return "jpg";
$unpacked = unpack("H16", $data);
if (array_pop($unpacked) == '89504e470d0a1a0a') return "png";

return false;
}

But i can't understand how to add this code in redactorjs file to check the image. i have added this code on image-processor.php but no result.
I have added this code:

if (is_image($_FILES['file']['path']) == false){
die("Not an image at all");
};

Not sure is it working cause, if i add a movie instead of an image then the file get upload first and then happens nothing! i think it is a problem for server, what i want is to do something without being upload the file?

0

There are 0 best solutions below