Jump to content

How to check if a $byte_array contains data?


JeremyCanada26

Recommended Posts

function checkIfSuppliedImageDataIsValid()
{
//first, check that the byte_array isset, then make sure it's not empty, then make sure it contains valid image data
if(isset($this->byte_array) && !empty($this->byte_array) && imagecreatefromstring($this->byte_array))
{
	//passed in byte array is good
	return true;
} else
{
	//missing or invalid
	return false;
}
}

 

The above function is what i'm settling for, although I also see there might be another way to do it manually but I'm not technical enough to know how.

 

The first eight bytes of a PNG file always contain the following (decimal) values: 137 80 78 71 13 10 26 10

 

Taken from the png RFC page, http://www.faqs.org/rfcs/rfc2083.html, section, 3.1. PNG file signature

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.