0){ //output echo "{\"status\":\"" . $result . "\", \"message\":\"" . $message . "\"}"; exit(); } }//POST method ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// //GET requests with a deviceId should output all the images in the directory. //This JSON output is used to power an Image Gallery Screen. if(strtoupper($reqMethod) == "GET" && strlen($deviceId) > 0){ //start the JSON output $JSON = "{\"childItems\":["; //loop all the files in this directory and add image files to the JSON if(is_dir($imageDirPath)){ if($handle = opendir($imageDirPath)){ while (false !== ($file = readdir($handle))) { if(strlen($file) > 5){ //image files must end with .jpg, .jpgeg or .png $ext = substr(strrchr($file, '.'), 1); //get rid of invalid returns in file name $file = str_replace("\n\r", "", $file); $file = str_replace("\n", "", $file); $file = str_replace("\r", "", $file); if(strtoupper($ext) == "JPG" || strtoupper($ext) == "JPEG" || strtoupper($ext) == "PNG"){ $JSON .= "\n{\"itemId\":\"" . strtoupper(fnCreateGuid()) . "\","; $JSON .= "\"itemType\":\"BT_imageItem\", "; $JSON .= "\"imageName\":\"" . $file . "\","; $JSON .= "\"imageURL\":\"" . $urlToThisDirectory . "/" . $file . "\"},"; } } } } } //remove the comma after last image so JSON is valid $JSON = trim($JSON); if(substr(strtoupper($JSON), (strlen($JSON) - 1), 1) == ","){ $JSON = substr($JSON, 0, strlen($JSON) - 1); } //end the JSON $JSON .= "\n]}"; //print the output echo $JSON; exit(); }//GET method ///////////////////////////////////////////////////////////////////////////////////////////////////////// /*############################################################################################################ The HTML form below will only show if the deviceId variable is empty. The form is desiged to allow you to test the script using your regular browser. ############################################################################################################## */ ?> Sample Image Upload and Output

Use this page to test the web-server that handles your image uploads.


  1. Save this file to your PHP enabled webserver with a .php extension. Example: image-upload.php
  2. Be sure the directory you save it in has "write" permissions. This is necessary to save the images when they are uploaded.
  3. Using your regular browser on your computer, visit the web-address at the location you saved the file on your server. Example: http://www.mywebsite.com/imageuploader/image-upload.php
  4. Using your regular browser, test the script by uploading an image to make sure it works.
  5. After you confirm that your server is able to accept and save uploaded images, create an Image Gallery screen and set the dataURL to this file with the deviceId appended to the end. YOU MUST INCLUDE THE DEVICEID IN THE URL OR THE IMAGE GALLERY WILL NOT WORK. Example: http://www.mywebsite.com/imageuploader/image-upload.php?deviceId=[deviceId] THe mobile app will merge the actual deviceId.

If your PHP enabled web-server is setup properly and allows file uploads (the folder is writeable) you will see each image you upload in a list.

"/>

Images in this directory

5){ //image files must end with .jpg, .jpgeg or .png $ext = substr(strrchr($file, '.'), 1); if(strtoupper($ext) == "JPG" || strtoupper($ext) == "JPEG" || strtoupper($ext) == "PNG"){ echo "
"; } } } } } ?>