messages->create( $toPhoneNumber, array("from" => $fromPhoneNumber, "body" => $mmsMessage, "mediaUrl" => "http://cloudfotobooth.com/fotomaster/mirrormebooth/" . $new_file_path) );
echo "Sent";
}
else
{
echo "Wrong Password";
}
function saveOnTheServer( $toPhoneNumber )
{
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["Filedata"]["name"]);
$extension = end($temp);
if ((($_FILES["Filedata"]["type"] == "image/gif")
|| ($_FILES["Filedata"]["type"] == "image/jpeg")
|| ($_FILES["Filedata"]["type"] == "image/jpg")
|| ($_FILES["Filedata"]["type"] == "image/pjpeg")
|| ($_FILES["Filedata"]["type"] == "image/x-png")
|| ($_FILES["Filedata"]["type"] == "image/png"))
&& ($_FILES["Filedata"]["size"] < 20000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["Filedata"]["error"] > 0)
{
return null;
}
else
{
$dir = "temp/";
$new_file_path = $dir . $toPhoneNumber . "_" . $_FILES["Filedata"]["name"];
//$new_file_path = $dir . time() . "_" . $_FILES["Filedata"]["name"];
if (file_exists($new_file_path))
{
return null;
}
else
{
$filename = $_FILES["Filedata"]["tmp_name"];
list($img_width, $img_height) = getimagesize($filename);
if ( ! is_dir($dir) )
mkdir($dir,0777, true);
if(!move_uploaded_file($_FILES["Filedata"]["tmp_name"],$new_file_path))
{
echo "Upload File Fail!";
die();
}
$efilename = explode('.', $new_file_path);
$ext = $efilename[count($efilename) - 1];
$ext = lcfirst($ext);
if( $ext == "jpeg"
|| $ext == "jpg"
|| $ext == "pjpeg"
|| $ext == "x-png"
|| $ext == "png" )
{
try{
$image = imagecreatefromjpeg($new_file_path);
imagejpeg($image,$new_file_path,70);
}
catch (Exception $e)
{
//do nothing
}
}
else if($ext == "gif")
{
}
return $new_file_path;
}
}
}
else
{
echo "error: Invalid file";
die();
}
return null;
}
//Make sure to run this function after twitter fetch the photo to delete the image from your server, you can also do it in a cron job for example
function deleteFromTheServer($new_file_path)
{
unlink($new_file_path);
}
?>