#1 2016-11-13 08:29:56

edunt
Member
Registered: 2015-12-21
Posts: 258

Where is the samples uploaded/posted images and data saved?

Hi David,
I was just playing with camera 3 sample project and I took picture and upload.
Where is the image uploaded?

Offline

#2 2016-11-13 09:57:22

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Where is the samples uploaded/posted images and data saved?

Hello Ade,

edunt wrote:

Hi David,
I was just playing with camera 3 sample project and I took picture and upload.
Where is the image uploaded?

Certainly the "Camera*" samples upload the Base64 representation of the captured image into my own server, however, I just return the same Base64 string (as you can see) and never save the image in the server. This is also valid for any other upload/post sample. The samples' server just reply like an "echo" with the uploaded/posted data, but do not save any data into the server.

Is this what you want to know Ade?

Online

#3 2016-11-13 18:19:08

edunt
Member
Registered: 2015-12-21
Posts: 258

Re: Where is the samples uploaded/posted images and data saved?

Hi David,

Yes and also can you share ready-made PHP script for uploading images on the server.

eg. Something we can just specify the url and the folder name of where the images will be uploaded.

 if (!ValidateEmail($mailfrom))
      {
         $error .= "The specified email address is invalid!\n<br>";
      }

      $i = 0;
      while (list ($key, $val) = each ($_FILES))
      {
         if ($_FILES[$key]['name'] != "" and file_exists($_FILES[$key]['tmp_name']) and $_FILES[$key]['size'] > 0)
         {
            $upload_DstName[$i] = $_FILES[$key]['name'];
            $upload_SrcName[$i] = $_FILES[$key]['name'];
            $upload_Size[$i] = ($_FILES[$key]['size']);
            $upload_Temp[$i] = ($_FILES[$key]['tmp_name']);
            $upload_Type[$i] = ($_FILES[$key]['type']);
            $upload_Link[$i] = "$upload_folder/$upload_DstName[$i]";
            $upload_fieldname[$i] = $key;
            $upload_fieldname_final[$i] = ucwords(str_replace("_", " ", $key));
            $fieldvalue[$i] = $upload_Link[$i];
            $i++;
         }
         if ($upload_Size[$i] >= $max_filesize)
         {
            $error .= "The size of $key (file: $upload_SrcName[$i]) is bigger than the allowed " . $max_filesize/1024 . " Kbytes!\n";
         }
      }

      if (!empty($error))
      {
         $errorcode = file_get_contents($error_url);
         $replace = "##error##";
         $errorcode = str_replace($replace, $error, $errorcode);
         echo $errorcode;
         exit;
      }

      $uploadfolder = basename($upload_folder);
      for ($i = 0; $i < count($upload_DstName); $i++)
      {
         $uploadFile = $uploadfolder . "/" . $upload_DstName[$i];
         if (!is_dir(dirname($uploadFile)))
         {
            RecursiveMkdir(dirname($uploadFile));
         }
         else
         {
            chmod(dirname($uploadFile), 0777);
         }
         move_uploaded_file($upload_Temp[$i] , $uploadFile);
         chmod($uploadFile, 0644);
      }

      $internalfields = array ("submit", "reset", "send", "captcha_code");
      $message .= $eol;
      $message .= "IP Address : ";
      $message .= $_SERVER['REMOTE_ADDR'];
      $message .= $eol;
      foreach ($_POST as $key => $value)
      {
         if (!in_array(strtolower($key), $internalfields))
         {
            if (!is_array($value))
            {
               $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
            }
            else
            {
               $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
            }
         }
      }

      if (count($upload_SrcName) > 0)
      {
         $message .= "\nThe following files have been uploaded:\n";
         for ($i = 0; $i < count($upload_SrcName); $i++)
         {
            $message .= $upload_SrcName[$i] . ": " . $upload_Link[$i] . "\n";
         }
      }
      $body  = 'This is a multi-part message in MIME format.'.$eol.$eol;
      $body .= '--'.$boundary.$eol;
      $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
      $body .= 'Content-Transfer-Encoding: 8bit'.$eol;
      $body .= $eol.stripslashes($message).$eol;
      $body .= '--'.$boundary.'--'.$eol;
      mail($mailto, $subject, $body, $header);
      $autoresponder_header  = 'From: '.$autoresponder_from.$eol;
      $autoresponder_header .= 'Reply-To: '.$autoresponder_from.$eol;
      $autoresponder_header .= 'MIME-Version: 1.0'.$eol;
      $autoresponder_header .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
      $autoresponder_header .= 'Content-Transfer-Encoding: 8bit'.$eol;
      $autoresponder_header .= 'X-Mailer: PHP v'.phpversion().$eol;
      mail($mailfrom, $autoresponder_subject, $autoresponder_message, $autoresponder_header);
      header('Location: '.$success_url);
      exit;
   }

Last edited by edunt (2016-11-13 18:21:03)

Offline

#4 2016-11-13 18:26:03

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Where is the samples uploaded/posted images and data saved?

Hello Ade,

In this StackOverflow thread we can find some possible approach in PHP. Certainly just one function can do the job:

function base64_to_jpeg($base64_string, $output_file) {

    $ifp = fopen($output_file, "wb"); 

    $data = explode(',', $base64_string);

    fwrite($ifp, base64_decode($data[1])); 
    fclose($ifp); 

    return $output_file; 
}

Online

#5 2016-11-13 18:34:36

edunt
Member
Registered: 2015-12-21
Posts: 258

Re: Where is the samples uploaded/posted images and data saved?

Hi Ade,

Alright, good. what about PHP script function for uploading the converted image on to the webserver after conversion?

Last edited by edunt (2016-11-13 18:39:17)

Offline

#6 2016-11-13 18:49:11

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Where is the samples uploaded/posted images and data saved?

Hello Ade,

What the server receives is the Base64 string. If we pass that string to the above "base64_to_jpeg" function then the image is saved in the specified "output_file".

Online

#7 2016-12-02 08:40:41

edunt
Member
Registered: 2015-12-21
Posts: 258

Re: Where is the samples uploaded/posted images and data saved?

David wrote:

Hello Ade,

What the server receives is the Base64 string. If we pass that string to the above "base64_to_jpeg" function then the image is saved in the specified "output_file".

Alright thanks.

Offline

#8 2017-08-20 19:53:13

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,661
Website

Re: Where is the samples uploaded/posted images and data saved?

Hello to all,

I forget this thread... I only want to say, that, thanks to some more or less recent addition into the Camera control and the CameraDataToImage action, we can now send the Camera's captures as image files using an HttpClient control. Look at the "Camera5" sample to view this last stuff working. We can continue working with "Base64" strings, but, work with files is now possible too.

Online

#9 2017-08-20 23:19:31

edunt
Member
Registered: 2015-12-21
Posts: 258

Re: Where is the samples uploaded/posted images and data saved?

Hi David,

Thanks for the information.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.