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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.