Android Html5/java app: mosync gallery upload & send email -


im trying customize mosync photo gallery sample can find here , here.

this html/java app wich take snaphot , upload taken picture web server via php file ( in case file upload.php)

everythings works fine me add email field , ask user type email adress field before uploading. send out email picture attached want on server side (php) after upload complete.

i have tried add mail function (with pre defined sendto adress , link picture) upload.php file , works can't return status message on device telling user upload complete.this ennoying user don't know if process completed

i'm blocking on different steps: 1: how recuperate email adress typed user , passing upload.php 2: how add uploaded picture attachement , send user 3: how keep status message being displayed on device?

is here have encounter same questions? have experience sample mosync app?

thanks help

below upload.php file used:

<?php ini_set("display_errors", "1"); ini_set("log_errors", "1"); error_reporting(-1);   function mylog($message) { $file = 'mylog.txt'; // open file existing content $current = file_get_contents($file); // append line file $current .= "$message\n"; // write contents file file_put_contents($file, $current); }  function uploadphoto() { $targetpath = "test/" . basename($_files["file"]["name"]);  if (fileisok($_files["file"])) {     $success = move_uploaded_file($_files["file"]["tmp_name"], $targetpath);      if ($success)     {         echo "the file " . basename($_files["file"]["name"]) .         " has been uploaded";      }     else     {     echo "there error uploading file";     } } else { echo "not valid image file"; }  }  function fileisok($file) { return $file["size"] < 1500000     && fileisimage($file["name"]); }  function fileisimage($path) { return endswith($path, ".jpeg")     || endswith($path, ".jpg")     || endswith($path, ".png"); }  function endswith($haystack, $needle) { $expectedposition = strlen($haystack) - strlen($needle); return strripos($haystack, $needle, 0) === $expectedposition; }  function getphotourls() { /*// debugging. $urls = getlasttenphotourls(); foreach ($urls $url) {     echo "<a href='$url'>$url</a><br/>\n"; }*/  echo getphotourlsasjson(); }  function getphotourlsasjson() { $urls = getlasttenphotourls();  return json_encode($urls); }   // gets last ten photo urls. function getlasttenphotourls() {  $baseurl = "http:the url photos posted";  $basedir = "test/";  $files = array();  // add files table using last mod time key. if ($handle = opendir($basedir)) {     while (false !== ($file = readdir($handle)))     {         if ("." != $file && ".." != $file)         {             $files[filemtime($basedir . $file)] = $file;         }     }      closedir($handle); }  // sort mod time. ksort($files);  // last ones first. $files = array_reverse($files);  // list if urls. $urls = array();  // create list of urls recent files. $filecounter = 0; foreach ($files $file) {     ++$filecounter;     // ten recent files (100 many!).     if ($filecounter > 10)     {         // todo: move excessive files archive directory?         break;     }     array_push($urls, $baseurl . $file); }  return $urls; }  function sendhtmlemail($html,$from,$to,$subject) { $url="http:the url of posted photos; $mailto .= 'the email of user';  $html=" <table style='font-size:13px' width='700' border='0' cellspacing='0' cellpadding='3'> <tr> <td colspan='2'>dear friend,<br></td> </tr> <tr>   <td colspan='2' bgcolor='#ffffff'>attached, find picture taken during our     last event.</strong></td>     </tr> <tr>   <td colspan='2' bgcolor='#ffffff' width='250' >link <a  href=".$url.">gallery</a></td>       </tr>     </table>";  $from='<noreply@noreply.be>'; $subject='picture'; $to= $mailto; $headers = "from: $from\r\n";  $headers .= "mime-version: 1.0\r\n";  $headers .= //"--$boundary\r\n".             "content-type: text/html; charset=iso-8859-1\r\n";             //"content-transfer-encoding: base64\r\n\r\n";               mail($to,$subject,$html,$headers);  }    // if file data posted upload file, // else list of image urls.   if (isset($_files["file"])) {  sendhtmlemail($html,$from,$to,$subject); uploadphoto();     } else { getphotourls(); } ?> 

1: how pass email adress upload.php?

first, email address field on html page. assume added input field page-camera.html. modify following call pass on value mail addres field:

mosync.nativeui.calljs(   mosync.nativeui.main_webview,   "app.uploadphoto('" + mfileurl + "','" + emailaddress + "')"); 

this call function app.uploadphoto in index.html new parameter meail address, need modified well. rather using options.parame = null; use someting this:

app.uploadphoto = function(fileurl, emailaddress) {   var options = new fileuploadoptions();   options.filekey = "file";   options.filename = fileurl.substr(fileurl.lastindexof('/') + 1);   options.mimetype = app.getmimetype(options.filename);   //options.params = null;   options.params = { email: emailaddress };   // ... , rest of code function. } 

the general form of paraameter list this:

options.params = {param1: "value1", param2: "value2"}; 

then in php script, can access email address this:

$emailaddress = $_post["email"]; 

2: how add uploaded picture attachement , send user?

perhaps these questions can this:

insert image in mail body php send email image how attach , show image in mail using php?

3: how keep status message being displayed on device?

it may there error in php script, causing fail, , never executing uploadphoto. can debug see if case.

what return string output echo, passed on javascript in app.

the current photogallery app not display string, should really. in index.html, rather using this:

alert("photo uploaded"); 

this should used instead:

alert(result.response); 

this way can check result , pass data , if wish directly display result string user.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -