$error) { $uploaddir = 'E:\\xampp\\htdocs\\mmsServer\\upload\\'; $uploadfile = $uploaddir . basename($_FILES['MMSFile']['name'][$key]); $stringData .= " ** ".$_FILES['MMSFile']['tmp_name'][$key] . " => ".$uploadfile." ** \n"; if (move_uploaded_file($_FILES['MMSFile']['tmp_name'][$key], $uploadfile)) { $stringData .= "File is valid, and was successfully uploaded.\n"; //$stringData .= " -- ".preg_match('/jpg/',$uploadfile)." -- ".preg_match('/jpeg/',$uploadfile)." -- ".$uploadfile." -- "; if(preg_match('/jpg/',$uploadfile) || preg_match('/jpeg/',$uploadfile)){ $imgFile = $uploadfile; $stringData .= "using file: ".$imgFile . " | "; } } else { $stringData .= "Possible file upload attack!\n"; } } fwrite($fh, $stringData); if($imgFile != ""){ $fromNumber = $_REQUEST['MMSFrom']; $str = getPongrResponse($imgFile,$fromNumber); if(preg_match('/did not match anything/i',$str)) $str = "Congratulations! We didn't recognize your photo, but you've been entered for a chance to win a new Apple iPhone 4!"; get_web_page( "http://localhost:8800/Send%20Text%20Message.htm?PhoneNumber=$fromNumber&Text=".urlencode($str)."&InfoCharCounter=&PID=&DCS=&DestPort=&DelayUntil=&Submit=Submit",$fromNumber); $stringData = "http://localhost:8800/Send%20Text%20Message.htm?PhoneNumber=$fromNumber&Text=".urlencode($str)."&InfoCharCounter=&PID=&DCS=&DestPort=&DelayUntil=&Submit=Submit"; } fwrite($fh, $stringData); /*$returnHttp500OnError = True; $errorFlag = False; $dateString = date("YmdHis"); $savedImageFile = False; if (!isset($_REQUEST['MMSFrom']) || !$_REQUEST['MMSFrom']) { echo "ERROR: MMSFrom variable (sender) is not set"; $stringData .= "ERROR: MMSFrom variable (sender) is not set"; $errorFlag = True; } if (!isset($_REQUEST['MMSSubject']) || !$_REQUEST['MMSSubject']) { $MMSSubject = "Multimedia Message"; } else { $MMSSubject = $_REQUEST['MMSSubject']; } if (!$errorFlag) { $errorFlag = True; if ($_FILES["MMSFile"] && is_array($_FILES["MMSFile"]) && count($_FILES["MMSFile"])) { foreach ($_FILES["MMSFile"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $errorFlag = False; } } } if ($errorFlag) { echo "ERROR: Request does not include any uploaded files!"; $stringData .= "ERROR: Request does not include any uploaded files!"; } } if (!$errorFlag) { $user_path = $upload_path . $_REQUEST['MMSFrom']; if (!@file_exists ($user_path)) { @mkdir ($user_path); } $user_path = $user_path . "\\"; $tmp_filename = $user_path . "temp.tmp"; $tmp_handle = @fopen ($tmp_filename, "w+"); if (!$tmp_handle) { if ($returnHttp500OnError) header("HTTP/1.0 500 Internal Error"); echo "ERROR: Cannot create files in upload directory " . $user_path; $stringData .= "ERROR: Cannot create files in upload directory " . $user_path; $errorFlag = True; } else { fclose ($tmp_handle); @unlink ($tmp_filename); } } if (!$errorFlag) { $image_path = $user_path . $dateString; if (!@file_exists ($image_path)) { @mkdir ($image_path); } $image_path = $image_path . "\\"; $tmp_filename = $image_path . "temp.tmp"; $tmp_handle = @fopen ($tmp_filename, "w+"); if (!$tmp_handle) { if ($returnHttp500OnError) header("HTTP/1.0 500 Internal Error"); echo "ERROR: Cannot create files in upload directory " . $image_path; $stringData .= "ERROR: Cannot create files in upload directory " . $image_path; $errorFlag = True; } else { fclose ($tmp_handle); @unlink ($tmp_filename); } } if (!$errorFlag) { $msglogTxt = $user_path . "msglog.txt"; $msglogTmp = $user_path . "msglog.tmp"; if (@file_exists ($msglogTmp)) { @unlink ($msglogTmp); } if (@file_exists ($msglogTxt)) { if (!@copy ($msglogTxt, $msglogTmp)) { if ($returnHttp500OnError) header("HTTP/1.0 500 Internal Error"); echo "ERROR: Cannot create temporary file in upload directory " . $user_path; $stringData .= "ERROR: Cannot create temporary file in upload directory " . $user_path; $errorFlag = True; } } if (!$errorFlag) { $msglogTxt_handle = @fopen ($msglogTxt, "w+"); if (!$msglogTxt_handle) { if ($returnHttp500OnError) header("HTTP/1.0 500 Internal Error"); echo "ERROR: Cannot create temporary file in upload directory " . $user_path; $stringData .= "ERROR: Cannot create temporary file in upload directory " . $user_path; $errorFlag = True; } } if (!$errorFlag) { fwrite ($msglogTxt_handle, "\r\n"); fwrite ($msglogTxt_handle, "

" . $MMSSubject . "

\r\n"); fwrite ($msglogTxt_handle, "

" . date("F j, Y, H:i") . "

\r\n"); foreach ($_FILES["MMSFile"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["MMSFile"]["tmp_name"][$key]; if (!strcmp (strtolower($_FILES["MMSFile"]["type"][$key]), "text/plain")) { fwrite ($msglogTxt_handle, "

" . file_get_contents ($tmp_name) . "

\r\n"); echo "The file ". basename( $_FILES["MMSFile"]["name"][$key]). " has been uploaded
"; } else if (!strcmp (strtolower($_FILES["MMSFile"]["type"][$key]), "application/smil")) { echo "The file ". basename( $_FILES["MMSFile"]["name"][$key]). " has been skipped
"; } else { $new_name = $image_path . basename( $_FILES["MMSFile"]["name"][$key]); if (@move_uploaded_file($tmp_name, $new_name)) { $savedImageFile = True; echo "The file ". basename( $_FILES["MMSFile"]["name"][$key]). " has been uploaded
"; if (!strncmp (strtolower($_FILES["MMSFile"]["type"][$key]), "image/", 6)) { fwrite ($msglogTxt_handle, "

\r\n"); } else if (!strncmp (strtolower($_FILES["MMSFile"]["type"][$key]), "video/", 6)) { fwrite ($msglogTxt_handle, "

Video attachment: " . basename($_FILES["MMSFile"]["name"][$key]) . "

\r\n"); } else { fwrite ($msglogTxt_handle, "

File attachment: " . basename($_FILES["MMSFile"]["name"][$key]) . "

\r\n"); } } else { echo "Error uploading file ". basename( $_FILES["MMSFile"]["name"][$key]) . "
"; $stringData .= "Error uploading file ". basename( $_FILES["MMSFile"]["name"][$key]) . "
"; } } } } fwrite ($msglogTxt_handle, "\r\n"); if (@file_exists ($msglogTmp)) { fwrite ($msglogTxt_handle, file_get_contents ($msglogTmp)); @unlink ($msglogTmp); } fclose ($msglogTxt_handle); } if (!$savedImageFile && $image_path) { @rmdir ($user_path . $dateString); } } if (!$errorFlag) { $htmlFile = $user_path . "index.html"; $htmlFile_handle = @fopen ($htmlFile, "w+"); if (!$htmlFile_handle) { if ($returnHttp500OnError) header("HTTP/1.0 500 Internal Error"); echo "ERROR: Cannot create file in user upload directory " . $user_path; $stringData .= "ERROR: Cannot create file in user upload directory " . $user_path; $errorFlag = True; } else { fwrite ($htmlFile_handle, "\r\n\r\nMMS Message Log for " . $_REQUEST['MMSFrom'] . "\r\n\r\n\r\n"); fwrite ($htmlFile_handle, "

MMS Message Log for " . $_REQUEST['MMSFrom'] . "

\r\n"); fwrite ($htmlFile_handle, file_get_contents ($user_path . "msglog.txt")); fwrite ($htmlFile_handle, "\r\n\r\n"); fclose ($htmlFile_handle); } } */ fclose($fh); function describeAnidatedArray($array) { $buf = ''; foreach($array as $key => $value) { $buf .= " | ".$key." => ".$value." | "; } return $buf; } function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "local", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } function getPongrResponse($filePath,$fromNum){ $ch = curl_init(); $post = array( 'app_name'=>"phone", 'sent_to'=>$_REQUEST['PhoneNumber'], 'app_user_id'=>$fromNum, 'filename'=>'meh.jpg', 'file'=>"@$filePath", ); //$post["app_name"] = "phone"; $ch = curl_init($APP); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, "http://v1.api.adcondor.com/matches"); // curl_setopt($ch, CURLOPT_URL, "http://localhost/mmsServer/echo.php"); $postResult = curl_exec($ch); curl_close($ch); $searchableResult = str_replace("","\n",str_replace("\n","",str_replace("\r\n","",str_replace("\t","",$postResult)))); //echo $searchableResult; if(preg_match('/id="no_match"/',$postResult)) return "This image did not match anything in our system."; else{ preg_match('/"text_content">.*<\/dd>/msi',$postResult,$matchList); if(count($matchList) == 0) return "This image did not match anything in our system."; else{ $split = explode('',$matchList[0]); $split2 = explode('>',$split[0]); return($split2[1]); } } return; } ?>