Following code achieves this:
$photoFile = $messageText = "";
foreach($mms->PARTS as $mmsPart)
{
$type = $mmsPart->CONTENTTYPE;
// Check if this is an image type data
if ($photoFile == "" && eregi("jpg|jpeg|gif|png", $type))
{
$ext = substr($type, strrpos($type, "/")+1);
$photoFile = time().".$ext";
$mmsPart->save($photoFile);
}
// Check if this is a plain text data,
// we don't want any other type of text
if ($messageText == "" && eregi("plain", $type))
{
$messageText = $mmsPart->DATA;
}
// If we got both files, we can save the info
// and complete the task!
if ($photoFile != "" && $messageText != "")
{
$info['from'] = $mms->FROM;
$info['subject'] = $mms->SUBJECT;
$info['photo'] = $photoFile;
$info['message'] = $messageText;
// Code to save to DB
echo "
Saved the new message
";
print_r($info); // For debugging only!
break;
}
}
Adding Spice to Messages: MMS
[ 136 ]
4. When we execute the code now, it will pick up the user.mms message,
process it, and show us the from and subject headers, and the message. The
photo file would have been saved as somenumber.jpg, where the number is
actually the UNIX Timestamp of when we processed the message.
Pages:
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183