php - How to catch str_get_html (Simple HTML Dom) error if fails to retrieve when larger than MAX_FILE_SIZE
Get the solution ↓↓↓I have an issue with a part of my script that retrieves emails from AWS SES S2 Bucket and when getting the body of the email it looks for Base64 inline images and converts it to an image file and then I upload that image to an S3 bucket and then change thesrc
of the image to that URL.
The issue is that sometimes an email will contain an inline image and/or files that is larger than myMAX_FILE_SIZE
in mysimple_html_dom.php
file. Of course, I could just increase the size, but ultimately I have to put a cap as to how large of an email I am willing to parse.
I have messed around trying to do atry
andcatch
which does not seem to work.
I have also tried doing
$message = str_get_html($body);
if ($message) {
// process email
} else {
// Email to big skip images.
}
but that has no chance to even check for an error since the script will break at$message = str_get_html($body);
Is there a method to catch an error onstr_get_html()
?
What I have done
In my effort to combat this issue I have done the following
$size = mb_strlen($body_of_email, '8bit');
if ($size < 25000000) {
$message = str_get_html($string);
}
The$message
is stored in a MySQL table which is how I am retrieving it.
The only concern I have is that I am not sure the potential for afalse positive
could occur usingmb_strlen
on$message
from MySQL and the possibility of getting a different size usingmb_strlenm
after getting the string withstr_get_html($message)
which is simple HTML dom. I have tested both ways and they do produce the same number.
Is there anything I need to be aware of for potential issues that can arise?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.