help with mms code modification.

Discussion in 'PHP' started by izlik, Apr 16, 2007.

  1. #1
    hey there.

    i have a page where people can send mms in pictures for free and they get shown on my page, the code bellow was provided by my host wich dont help me with any modifications, the code saves the imiage with a uniqe ID in /data/ and also adds the ID, cell number and message to the mysql database, atm the message you provide for my script to regonice it is save in the collumn "message" now i wonder how i can make the seccond message writen to be save in "message2" collumn

    like if they write "mmspicture check my nice car" "mmspicture" should be save in "message" and "check my nice car" should be save in "message2"

    <?php
    
    require_once('Mail/mimeDecode.php');
    
    $MYSQL_HOST = 'aaa';
    $MYSQL_USER = 'aaa';
    $MYSQL_PASSWORD = 'aaa';
    $MYSQL_DATABASE = 'aaa';
    
    error_reporting(0);
    
    mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD);
    mysql_select_db($MYSQL_DATABASE);
    
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $mms = new MMSDecoder();
        //debug only
        //echo "<hr/><pre>".print_r($mms, true)."</pre><hr/>";
    
        $message = mysql_real_escape_string($mms->subject);
        $phonenr = mysql_real_escape_string($mms->number);
        $tariff  = isset($_POST['tariff']) ? (int)$_POST['tariff'] : 0;
    
        foreach ($mms->parts as $part) {
            if ($part['type'] == 'image/jpeg'){
                $sql = "INSERT
                        INTO mms
                            (sender,message,tariff,tstamp)
                        VALUES
                        ('%s','%s',%d,NOW())";
                $sql = sprintf($sql,$phonenr,$message,$tariff);
                // execute
                $res = mysql_query($sql) or die(mysql_error());
        
                // save image in /data/
                $filename = 'data/'.mysql_insert_id().'.jpeg';
                file_put_contents($filename,$part['body']);
            } else {
            //do nothing
            } //close internal if
        }    //close foreach
    } //close master If
    ////////////////////////////////////////////////////////////////
    
    class MMSDecoder {
        var $subject;
        var $number;
        var $parts;
    
        function MMSDecoder() {
            
    
    // the text that matched your mmssubjectcode -> (Wich i set to "mmspicture"
            $this->subject = $_SERVER['HTTP_MOSMS_SUBJECT'];
            
    
    // senders phonenummber
            $this->number = $_SERVER['HTTP_MOSMS_NUMBER'];        
    
            
    
    // mms message from the phone coded in MIME
            $mimedata = file_get_contents('php://input');
            $headers  = "Content-Type: {$_SERVER['CONTENT_TYPE']}\n";
            $headers .= "Content-Length: {$_SERVER['CONTENT_LENGTH']}\n";
    
    // Decode the mms message
            $params = array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers'=> true);
            $decoder = new Mail_mimeDecode($headers . "\n" . $mimedata);
            $decoded = $decoder->decode($params);
                    
            foreach($decoded->parts as $part) {
                $temp = array();
                // MIME-typ till exempel: text/plain, image/jpeg, application/smil
                $temp['type'] = $part->ctype_primary. '/' . $part->ctype_secondary;
                
                // content-id,
                if(isset($part->headers['content-id'])) {
                    $temp['cid'] = trim($part->headers['content-id'],'<>');
                }
                
                if (isset($part->d_parameters['filename'])) {
                    $temp['filename'] = $part->d_parameters['filename'];
                }
                $temp['body'] = $part->body;
                $this->parts[] = $temp;
            }
    echo 'Thanks for your mms, it will soon be shown.   ';
        }
    }
    
    ?>
    Code (markup):
     
    izlik, Apr 16, 2007 IP