0

there I have some img tags ..I want read content of their src.

in some src I have binery code instead normal src like this:

 data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0//wAARCAIRA6wDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL...

Is there any way I detect if it is binary image?

I try this:

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $fileDIR);
finfo_close($finfo);

but it return image/jpeg ...

1 Answer 1

1

If I got your problem right, you want to be able to distinguish between something like

  • <img src="path/to/myimage.jpg" />

and

  • <img src="data:image/jpeg;base64,/9j/4A..." />

when analysing a HTML file using PHP, is this correct?

If so, you could look at the contents of the src attribute of the img and find out whether it starts with "data:". If (and only if) this is the case, you can assume that a binary image follows, see details here.

So, if you stumble upon a data: at the beginning of the src content, you can get the image by parsing the rest of it (possible regarding the base64 encoding and/or charset given, see here again). Else, you can access the image "normally" by the link in the src.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.