{"id":97893,"date":"2023-03-27T10:58:56","date_gmt":"2023-03-27T10:58:56","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=97893"},"modified":"2024-06-16T15:00:16","modified_gmt":"2024-06-16T15:00:16","slug":"esp32-cam-post-image-photo-server","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-cam-post-image-photo-server\/","title":{"rendered":"ESP32-CAM Post Images to Local or Cloud Server using PHP (Photo Manager)"},"content":{"rendered":"\n<p>Learn how to make HTTP POST requests using the ESP32-CAM board with Arduino IDE to send photos to a server. We\u2019ll show how to post a JPG\/JPEG image to a local server (Raspberry Pi LAMP server) or to a cloud server (that you can access from anywhere). The photos will be displayed in a gallery where you can view or delete the photos. To save the images in the server and create the gallery, we&#8217;ll use PHP scripts.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?resize=1024%2C576&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Board Send Post Images to Local Cloud Server HTTP POST Arduino IDE\" class=\"wp-image-129728\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\">Updated on 27 March 2023<\/p>\n\n\n\n<p>To build this project, you need to follow the next steps. Follow the LAMP Server or the Hosting Server instructions depending on if you want to access the photos locally or from anywhere.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Hosting your PHP Application\n<ol class=\"wp-block-list\">\n<li><a href=\"#1-1\">Raspberry Pi LAMP Server (local access)<\/a><\/li>\n\n\n\n<li><a href=\"#1-2\">Hosting Server (access from anywhere)<\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>PHP scripts to save and display photos in the server\n<ol class=\"wp-block-list\">\n<li><a href=\"#2-1\">Raspberry Pi LAMP Server (local access)<\/a><\/li>\n\n\n\n<li><a href=\"#2-2\">Hosting Server (access from anywhere)<\/a><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><a href=\"#3\">Program the ESP32-CAM with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"#4\">Testing and Final Demonstration<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">1. Hosting Your PHP Application<\/h2>\n\n\n\n<p>The goal of this project is to have a local or cloud server to store and access your ESP32-CAM photos. <\/p>\n\n\n\n<p id=\"1-1\"><strong>1. Raspberry Pi local server<\/strong>:<\/p>\n\n\n\n<p>With a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">Raspberry Pi LAMP server<\/a>, you can access your images locally (as illustrated below).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"900\" height=\"806\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Raspberry-Pi-LAMP-Server-PHP-gallery-Script-Arduino.png?resize=900%2C806&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Board Send Photo Image to Raspberry Pi LAMP Server PHP gallery Script Arduino\" class=\"wp-image-97922\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Raspberry-Pi-LAMP-Server-PHP-gallery-Script-Arduino.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Raspberry-Pi-LAMP-Server-PHP-gallery-Script-Arduino.png?resize=300%2C269&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Raspberry-Pi-LAMP-Server-PHP-gallery-Script-Arduino.png?resize=768%2C688&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>You can run a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">LAMP (Linux, Apache, MySQL, PHP) server<\/a> on a Raspberry Pi to <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-raspberry-pi-lamp-server\/\">access data in your local network<\/a>. Raspberry Pi LAMP Server: Local Linux server that you use to access your images locally.<\/li>\n<\/ul>\n\n\n\n<p style=\"text-align:center\"><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\" target=\"_blank\" class=\"button\" rel=\"noopener noreferrer\">Setup Local RPi LAMP Server \u00bb<\/a><\/p>\n\n\n\n<p id=\"1-2\"><strong>2. Cloud server (Bluehost hosting solution)<\/strong><\/p>\n\n\n\n<p>You also can visualize the ESP32-CAM photos from anywhere in the world by accessing your own server + domain. Here&#8217;s a high level overview on how it works:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"900\" height=\"775\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Cloud-Server-PHP-gallery-Script-Arduino.png?resize=900%2C775&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Board Send Photo Image to Cloud Server PHP gallery Script Arduino\" class=\"wp-image-97920\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Cloud-Server-PHP-gallery-Script-Arduino.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Cloud-Server-PHP-gallery-Script-Arduino.png?resize=300%2C258&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Send-Photo-Image-to-Cloud-Server-PHP-gallery-Script-Arduino.png?resize=768%2C661&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">Bluehost (user-friendly with cPanel)<\/a>: free domain name when you sign up for the 3-year plan. I recommend choosing the unlimited websites option; Note that any hosting service that offers PHP will work with this tutorial. If you don&#8217;t have a hosting account, I recommend <a href=\"https:\/\/randomnerdtutorials.com\/bluehost\">signing up for Bluehost<\/a>.<\/li>\n<\/ul>\n\n\n\n<p style=\"text-align:center\"><a href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\" class=\"button\" rel=\"noopener noreferrer\">Get Hosting and Domain Name with Bluehost \u00bb<\/a><\/p>\n\n\n\n<p>When buying a hosting account, you&#8217;ll also have to purchase a domain name. This is what makes this project interesting: you&#8217;ll be able to go your domain name (http:\/\/example.com) and see your ESP32-CAM photos. If you like our projects, you might consider signing up to Bluehost, because you&#8217;ll be supporting our work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTTP POST Request Method<\/h2>\n\n\n\n<p>The Hypertext Transfer Protocol (HTTP) works as a request-response protocol between a client and server. Here\u2019s an example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The ESP32 (client) submits an HTTP request to a Server (for example: local RPi Lamp Server or example.com);<\/li>\n\n\n\n<li>The server returns a response to the ESP32 (client);<\/li>\n<\/ul>\n\n\n\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-http-get-post-arduino\/\">HTTP POST<\/a><\/strong> is used to send data to a server to create\/update a resource. For example, publish an image to a server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>POST \/upload.php HTTP\/1.1\nHost: example.com\nContent-Type: image\/jpeg<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-1\">2.1. Preparing Your <em>.php<\/em> Files and <em>uploads<\/em> Folder (Raspberry Pi LAMP Server)<\/h2>\n\n\n\n<p>This section prepares your <em>.php<\/em> files and <em>uploads<\/em> folder for your Raspberry Pi LAMP Server. If you&#8217;re using your own server + domain name, skip to the next section.<\/p>\n\n\n\n<p>Having a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">Raspberry Pi running Apache and PHP<\/a>, in the Raspberry Pi board terminal window navigate to the <em>\/var\/www\/html\/<\/em> directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~ $ cd \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p>Create a new folder called <em>uploads<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ mkdir uploads\npi@raspberrypi:\/var\/www\/html $ ls\nuploads<\/code><\/pre>\n\n\n\n<p>At the moment, <em>\/var\/www\/html<\/em> is owned by root, use the next commands to change to the pi user and give it all permissions so that you can save photos using a PHP script later on.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R pi:pi \/var\/www\/html\nchmod -R 777 \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p>Finally, create a new <em>upload.php<\/em> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ nano upload.php<\/code><\/pre>\n\n\n\n<p>This PHP script is responsible for receiving incoming images from the ESP32-CAM, rename the images with a timestamp and store them in the <em>uploads <\/em>folder. Edit the newly created file (<em>upload.php<\/em>) and copy the following snippet:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;?php\r\n\/\/ Rui Santos\r\n\/\/ Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n\/\/ Code Based on this example: w3schools.com\/php\/php_file_upload.asp\r\n\r\n$target_dir = &quot;uploads\/&quot;;\r\n$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));\r\n$target_file = $target_dir . date('Y.m.d_H:i:s_', $datum) . basename($_FILES[&quot;imageFile&quot;][&quot;name&quot;]);\r\n$uploadOk = 1;\r\n$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));\r\n\r\n\/\/ Check if image file is a actual image or fake image\r\nif(isset($_POST[&quot;submit&quot;])) {\r\n  $check = getimagesize($_FILES[&quot;imageFile&quot;][&quot;tmp_name&quot;]);\r\n  if($check !== false) {\r\n    echo &quot;File is an image - &quot; . $check[&quot;mime&quot;] . &quot;.&quot;;\r\n    $uploadOk = 1;\r\n  }\r\n  else {\r\n    echo &quot;File is not an image.&quot;;\r\n    $uploadOk = 0;\r\n  }\r\n}\r\n\r\n\/\/ Check if file already exists\r\nif (file_exists($target_file)) {\r\n  echo &quot;Sorry, file already exists.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Check file size\r\nif ($_FILES[&quot;imageFile&quot;][&quot;size&quot;] &gt; 500000) {\r\n  echo &quot;Sorry, your file is too large.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Allow certain file formats\r\nif($imageFileType != &quot;jpg&quot; &amp;&amp; $imageFileType != &quot;png&quot; &amp;&amp; $imageFileType != &quot;jpeg&quot;\r\n&amp;&amp; $imageFileType != &quot;gif&quot; ) {\r\n  echo &quot;Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Check if $uploadOk is set to 0 by an error\r\nif ($uploadOk == 0) {\r\n  echo &quot;Sorry, your file was not uploaded.&quot;;\r\n\/\/ if everything is ok, try to upload file\r\n}\r\nelse {\r\n  if (move_uploaded_file($_FILES[&quot;imageFile&quot;][&quot;tmp_name&quot;], $target_file)) {\r\n    echo &quot;The file &quot;. basename( $_FILES[&quot;imageFile&quot;][&quot;name&quot;]). &quot; has been uploaded.&quot;;\r\n  }\r\n  else {\r\n    echo &quot;Sorry, there was an error uploading your file.&quot;;\r\n  }\r\n}\r\n?&gt;\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/upload.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Your <em>upload.php<\/em> file should look like this. Save your file and exit (Ctrl+X, Y, and Enter key):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"957\" height=\"978\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/upload-php-script-save-images-to-server-ESP32-CAM.png?resize=957%2C978&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Upload images to server local or cloud using the ESP32-CAM board Arduino IDE upload.php file\" class=\"wp-image-97897\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/upload-php-script-save-images-to-server-ESP32-CAM.png?w=957&amp;quality=100&amp;strip=all&amp;ssl=1 957w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/upload-php-script-save-images-to-server-ESP32-CAM.png?resize=294%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 294w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/upload-php-script-save-images-to-server-ESP32-CAM.png?resize=768%2C785&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 957px) 100vw, 957px\" \/><\/figure><\/div>\n\n\n<p>Then, create a new <em>gallery.php<\/em> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:\/var\/www\/html $ nano gallery.php<\/code><\/pre>\n\n\n\n<p>Edit the newly created file (<em>gallery.php<\/em>) and copy the following snippet:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;!-- \r\n  Rui Santos\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n--&gt;\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;ESP32-CAM Photo Gallery&lt;\/title&gt;\r\n  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\r\n  &lt;style&gt;\r\n    .flex-container {\r\n      display: flex;\r\n      flex-wrap: wrap;\r\n    }\r\n    .flex-container &gt; div {\r\n      text-align: center;\r\n      margin: 10px;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;&lt;body&gt;\r\n&lt;h2&gt;ESP32-CAM Photo Gallery&lt;\/h2&gt;\r\n&lt;?php\r\n  \/\/ Image extensions\r\n  $image_extensions = array(&quot;png&quot;,&quot;jpg&quot;,&quot;jpeg&quot;,&quot;gif&quot;);\r\n\r\n  \/\/ Check delete HTTP GET request - remove images\r\n  if(isset($_GET[&quot;delete&quot;])){\r\n    $imageFileType = strtolower(pathinfo($_GET[&quot;delete&quot;],PATHINFO_EXTENSION));\r\n    if (file_exists($_GET[&quot;delete&quot;]) &amp;&amp; ($imageFileType == &quot;jpg&quot; ||  $imageFileType == &quot;png&quot; ||  $imageFileType == &quot;jpeg&quot;) ) {\r\n      echo &quot;File found and deleted: &quot; .  $_GET[&quot;delete&quot;];\r\n      unlink($_GET[&quot;delete&quot;]);\r\n    }\r\n    else {\r\n      echo 'File not found - &lt;a href=&quot;gallery.php&quot;&gt;refresh&lt;\/a&gt;';\r\n    }\r\n  }\r\n  \/\/ Target directory\r\n  $dir = 'uploads\/';\r\n  if (is_dir($dir)){\r\n    echo '&lt;div class=&quot;flex-container&quot;&gt;';\r\n    $count = 1;\r\n    $files = scandir($dir);\r\n    rsort($files);\r\n    foreach ($files as $file) {\r\n      if ($file != '.' &amp;&amp; $file != '..') {?&gt;\r\n        &lt;div&gt;\r\n          &lt;p&gt;&lt;a href=&quot;gallery.php?delete=&lt;?php echo $dir . $file; ?&gt;&quot;&gt;Delete file&lt;\/a&gt; - &lt;?php echo $file; ?&gt;&lt;\/p&gt;\r\n          &lt;a href=&quot;&lt;?php echo $dir . $file; ?&gt;&quot;&gt;\r\n            &lt;img src=&quot;&lt;?php echo $dir . $file; ?&gt;&quot; style=&quot;width: 350px;&quot; alt=&quot;&quot; title=&quot;&quot;\/&gt;\r\n          &lt;\/a&gt;\r\n       &lt;\/div&gt;\r\n&lt;?php\r\n       $count++;\r\n      }\r\n    }\r\n  }\r\n  if($count==1) { echo &quot;&lt;p&gt;No images found&lt;\/p&gt;&quot;; } \r\n?&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/gallery.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This PHP script is responsible for displaying the images on the gallery. Your <em>gallery.php<\/em> file should look like this. Save your file and exit (Ctrl+X, Y, and Enter key):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"893\" height=\"642\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/gallery-php-script-save-images-to-server-ESP32-CAM.png?resize=893%2C642&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"gallery PHP script save and view images server ESP32-CAM\" class=\"wp-image-97940\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/gallery-php-script-save-images-to-server-ESP32-CAM.png?w=893&amp;quality=100&amp;strip=all&amp;ssl=1 893w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/gallery-php-script-save-images-to-server-ESP32-CAM.png?resize=300%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/gallery-php-script-save-images-to-server-ESP32-CAM.png?resize=768%2C552&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 893px) 100vw, 893px\" \/><\/figure><\/div>\n\n\n<h2 id=\"2-2\">2.2. Preparing Your <em>.php<\/em> Files and <em>uploads<\/em> Folder (Hosting Service)<\/h2>\n\n\n\n<p>If you prefer to run your server remotely and access the photos from anywhere, you need a hosting account. After signing up for a&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">hosting account and setting up a domain name<\/a>, you can login to your cPanel or similar dashboard. After that, open the File Manager.<\/p>\n\n\n\n<p>Open the \u201c<strong>Advanced<\/strong>\u201d tab and select &#8220;<strong>File Manager<\/strong>&#8220;:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"543\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Advanced-open-File-Manager.png?resize=794%2C543&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Bluehost open advanced and file manager files to create upload.php file and uploads folder\" class=\"wp-image-97903\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Advanced-open-File-Manager.png?w=794&amp;quality=100&amp;strip=all&amp;ssl=1 794w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Advanced-open-File-Manager.png?resize=300%2C205&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Advanced-open-File-Manager.png?resize=768%2C525&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 794px) 100vw, 794px\" \/><\/figure><\/div>\n\n\n<p>Then, select the&nbsp;<strong>public_html<\/strong>&nbsp;option. Press the &#8220;<strong>+ File<\/strong>&#8221; button to create a new <em>upload.php<\/em> file and a new <em>gallery.php<\/em> file. Then, click the &#8220;<strong>+Folder<\/strong>&#8221; button to create the <em>Uploads <\/em>folder.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"346\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-CPanel-Create-New-Upload-PHP-File-Uploads-Folder.png?resize=849%2C346&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera board CPanel Create New Upload PHP File Uploads Folder\" class=\"wp-image-97904\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-CPanel-Create-New-Upload-PHP-File-Uploads-Folder.png?w=849&amp;quality=100&amp;strip=all&amp;ssl=1 849w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-CPanel-Create-New-Upload-PHP-File-Uploads-Folder.png?resize=300%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-CPanel-Create-New-Upload-PHP-File-Uploads-Folder.png?resize=768%2C313&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/figure><\/div>\n\n\n<p>With the three items created, edit the <em>upload.php<\/em> file:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"436\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-PHP-files-and-folder-created.png?resize=961%2C436&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera board CPanel Create New PHP Files and Uploads Folder\" class=\"wp-image-97926\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-PHP-files-and-folder-created.png?w=961&amp;quality=100&amp;strip=all&amp;ssl=1 961w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-PHP-files-and-folder-created.png?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-PHP-files-and-folder-created.png?resize=768%2C348&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 961px) 100vw, 961px\" \/><\/figure><\/div>\n\n\n<p>This PHP script is responsible for receiving incoming images from the ESP32-CAM, rename the images with a timestamp and store them in the <em>uploads <\/em>folder. Edit the newly created file (<em>upload.php<\/em>) and copy the following snippet:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;?php\r\n\/\/ Rui Santos\r\n\/\/ Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n\/\/ Code Based on this example: w3schools.com\/php\/php_file_upload.asp\r\n\r\n$target_dir = &quot;uploads\/&quot;;\r\n$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));\r\n$target_file = $target_dir . date('Y.m.d_H:i:s_', $datum) . basename($_FILES[&quot;imageFile&quot;][&quot;name&quot;]);\r\n$uploadOk = 1;\r\n$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));\r\n\r\n\/\/ Check if image file is a actual image or fake image\r\nif(isset($_POST[&quot;submit&quot;])) {\r\n  $check = getimagesize($_FILES[&quot;imageFile&quot;][&quot;tmp_name&quot;]);\r\n  if($check !== false) {\r\n    echo &quot;File is an image - &quot; . $check[&quot;mime&quot;] . &quot;.&quot;;\r\n    $uploadOk = 1;\r\n  }\r\n  else {\r\n    echo &quot;File is not an image.&quot;;\r\n    $uploadOk = 0;\r\n  }\r\n}\r\n\r\n\/\/ Check if file already exists\r\nif (file_exists($target_file)) {\r\n  echo &quot;Sorry, file already exists.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Check file size\r\nif ($_FILES[&quot;imageFile&quot;][&quot;size&quot;] &gt; 500000) {\r\n  echo &quot;Sorry, your file is too large.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Allow certain file formats\r\nif($imageFileType != &quot;jpg&quot; &amp;&amp; $imageFileType != &quot;png&quot; &amp;&amp; $imageFileType != &quot;jpeg&quot;\r\n&amp;&amp; $imageFileType != &quot;gif&quot; ) {\r\n  echo &quot;Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.&quot;;\r\n  $uploadOk = 0;\r\n}\r\n\r\n\/\/ Check if $uploadOk is set to 0 by an error\r\nif ($uploadOk == 0) {\r\n  echo &quot;Sorry, your file was not uploaded.&quot;;\r\n\/\/ if everything is ok, try to upload file\r\n}\r\nelse {\r\n  if (move_uploaded_file($_FILES[&quot;imageFile&quot;][&quot;tmp_name&quot;], $target_file)) {\r\n    echo &quot;The file &quot;. basename( $_FILES[&quot;imageFile&quot;][&quot;name&quot;]). &quot; has been uploaded.&quot;;\r\n  }\r\n  else {\r\n    echo &quot;Sorry, there was an error uploading your file.&quot;;\r\n  }\r\n}\r\n?&gt;\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/upload.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Save your file and exit.<\/p>\n\n\n\n<p>Then, edit the <em>gallery.php<\/em> file and copy the following snippet. This is responsible for displaying the images in the gallery.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;!-- \r\n  Rui Santos\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n--&gt;\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;ESP32-CAM Photo Gallery&lt;\/title&gt;\r\n  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\r\n  &lt;style&gt;\r\n    .flex-container {\r\n      display: flex;\r\n      flex-wrap: wrap;\r\n    }\r\n    .flex-container &gt; div {\r\n      text-align: center;\r\n      margin: 10px;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;&lt;body&gt;\r\n&lt;h2&gt;ESP32-CAM Photo Gallery&lt;\/h2&gt;\r\n&lt;?php\r\n  \/\/ Image extensions\r\n  $image_extensions = array(&quot;png&quot;,&quot;jpg&quot;,&quot;jpeg&quot;,&quot;gif&quot;);\r\n\r\n  \/\/ Check delete HTTP GET request - remove images\r\n  if(isset($_GET[&quot;delete&quot;])){\r\n    $imageFileType = strtolower(pathinfo($_GET[&quot;delete&quot;],PATHINFO_EXTENSION));\r\n    if (file_exists($_GET[&quot;delete&quot;]) &amp;&amp; ($imageFileType == &quot;jpg&quot; ||  $imageFileType == &quot;png&quot; ||  $imageFileType == &quot;jpeg&quot;) ) {\r\n      echo &quot;File found and deleted: &quot; .  $_GET[&quot;delete&quot;];\r\n      unlink($_GET[&quot;delete&quot;]);\r\n    }\r\n    else {\r\n      echo 'File not found - &lt;a href=&quot;gallery.php&quot;&gt;refresh&lt;\/a&gt;';\r\n    }\r\n  }\r\n  \/\/ Target directory\r\n  $dir = 'uploads\/';\r\n  if (is_dir($dir)){\r\n    echo '&lt;div class=&quot;flex-container&quot;&gt;';\r\n    $count = 1;\r\n    $files = scandir($dir);\r\n    rsort($files);\r\n    foreach ($files as $file) {\r\n      if ($file != '.' &amp;&amp; $file != '..') {?&gt;\r\n        &lt;div&gt;\r\n          &lt;p&gt;&lt;a href=&quot;gallery.php?delete=&lt;?php echo $dir . $file; ?&gt;&quot;&gt;Delete file&lt;\/a&gt; - &lt;?php echo $file; ?&gt;&lt;\/p&gt;\r\n          &lt;a href=&quot;&lt;?php echo $dir . $file; ?&gt;&quot;&gt;\r\n            &lt;img src=&quot;&lt;?php echo $dir . $file; ?&gt;&quot; style=&quot;width: 350px;&quot; alt=&quot;&quot; title=&quot;&quot;\/&gt;\r\n          &lt;\/a&gt;\r\n       &lt;\/div&gt;\r\n&lt;?php\r\n       $count++;\r\n      }\r\n    }\r\n  }\r\n  if($count==1) { echo &quot;&lt;p&gt;No images found&lt;\/p&gt;&quot;; } \r\n?&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/gallery.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Save your file and exit. That&#8217;s it! Your server is ready.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3\">3. ESP32-CAM HTTP Post Images\/Photos to Server<\/h2>\n\n\n\n<p>Now that you have your server ready (Raspberry Pi LAMP server or cloud server), it&#8217;s time to prepare the ESP32-CAM with the code to publish a new image to your server every 30 seconds. Before proceeding with this tutorial, make sure you complete the following prerequisites.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>To follow this tutorial you need the following components:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-cam\/\" target=\"_blank\">ESP32-CAM with OV2640<\/a><\/strong>&nbsp;\u2013 read&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/esp32-camera-cam-boards-review-comparison\/\" target=\"_blank\">Best ESP32-CAM Dev Boards<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\">FTDI programmer<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Female-to-female jumper wires<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-power-supply\/\" target=\"_blank\">5V power supply for ESP32-CAM<\/a><\/li>\n\n\n\n<li>Local server:\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-board\/\" target=\"_blank\">Raspberry Pi Board<\/a>&nbsp;&nbsp;\u2013 read&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-3-starter-kits\/\" target=\"_blank\">Best Raspberry Pi Starter Kits<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\">MicroSD Card \u2013 32GB Class10<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-power-supply\/\" target=\"_blank\">Raspberry Pi Power Supply (5V 2.5A)<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Cloud server (alternative): <a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">Bluehost<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arduino IDE<\/h3>\n\n\n\n<p>We\u2019ll program the&nbsp;<a href=\"https:\/\/makeradvisor.com\/tools\/esp32-cam\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32-CAM<\/a>&nbsp;using Arduino IDE, so make sure you have the ESP32 add-on installed.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp32-arduino-ide-2-0\/\" title=\"\">Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Check the PHP URL<\/h3>\n\n\n\n<p>You should try to open the Raspberry Pi local IP address or your external example.com domain name, followed by <strong>\/upload.php<\/strong> that should return:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.Sorry, your file was not uploaded.<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"326\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Upload-Files-Image.png?resize=705%2C326&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Testing the upload.php URL\" class=\"wp-image-97907\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Upload-Files-Image.png?w=705&amp;quality=100&amp;strip=all&amp;ssl=1 705w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Upload-Files-Image.png?resize=300%2C139&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/figure><\/div>\n\n\n<p>If you see that message save your URL\/domain name and path, your server should be ready and you can continue with this guide.<\/p>\n\n\n\n<p>Additionally, try to access the <strong>\/gallery.php <\/strong>path. You should get something as shown below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"411\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-gallery-PHP-file-view-delete-photos.png?resize=752%2C411&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Board gallery PHP file view delete photos\" class=\"wp-image-97935\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-gallery-PHP-file-view-delete-photos.png?w=752&amp;quality=100&amp;strip=all&amp;ssl=1 752w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-gallery-PHP-file-view-delete-photos.png?resize=300%2C164&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">ESP32-CAM Code<\/h3>\n\n\n\n<p>If you&#8217;re using a local server without TLS\/SSL, or a cloud server that doesn&#8217;t support HTTPS, use the <a href=\"#ESP32-CAM-HTTP-POST-Request\" title=\"\">HTTP POST Request Code<\/a>.<\/p>\n\n\n\n<p>If you&#8217;re using a cloud server that requires HTTPS requests, use this code instead: <a href=\"#ESP32-CAM-HTTPS-POST-Request\" title=\"\">HTTPS POST Request Code<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ESP32-CAM-HTTP-POST-Request\">ESP32-CAM HTTP POST Request<\/h4>\n\n\n\n<p>The next sketch posts the image to a server using HTTP POST. Copy the code below to your Arduino IDE. <\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n*\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;WiFi.h&gt;\r\n#include &quot;soc\/soc.h&quot;\r\n#include &quot;soc\/rtc_cntl_reg.h&quot;\r\n#include &quot;esp_camera.h&quot;\r\n\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\nString serverName = &quot;192.168.1.XXX&quot;;   \/\/ REPLACE WITH YOUR Raspberry Pi IP ADDRESS\r\n\/\/String serverName = &quot;example.com&quot;;   \/\/ OR REPLACE WITH YOUR DOMAIN NAME\r\n\r\nString serverPath = &quot;\/upload.php&quot;;     \/\/ The default serverPath should be upload.php\r\n\r\nconst int serverPort = 80;\r\n\r\nWiFiClient client;\r\n\r\n\/\/ CAMERA_MODEL_AI_THINKER\r\n#define PWDN_GPIO_NUM     32\r\n#define RESET_GPIO_NUM    -1\r\n#define XCLK_GPIO_NUM      0\r\n#define SIOD_GPIO_NUM     26\r\n#define SIOC_GPIO_NUM     27\r\n\r\n#define Y9_GPIO_NUM       35\r\n#define Y8_GPIO_NUM       34\r\n#define Y7_GPIO_NUM       39\r\n#define Y6_GPIO_NUM       36\r\n#define Y5_GPIO_NUM       21\r\n#define Y4_GPIO_NUM       19\r\n#define Y3_GPIO_NUM       18\r\n#define Y2_GPIO_NUM        5\r\n#define VSYNC_GPIO_NUM    25\r\n#define HREF_GPIO_NUM     23\r\n#define PCLK_GPIO_NUM     22\r\n\r\nconst int timerInterval = 30000;    \/\/ time between each HTTP POST image\r\nunsigned long previousMillis = 0;   \/\/ last time image was sent\r\n\r\nvoid setup() {\r\n  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); \r\n  Serial.begin(115200);\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  Serial.println();\r\n  Serial.print(&quot;Connecting to &quot;);\r\n  Serial.println(ssid);\r\n  WiFi.begin(ssid, password);  \r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print(&quot;.&quot;);\r\n    delay(500);\r\n  }\r\n  Serial.println();\r\n  Serial.print(&quot;ESP32-CAM IP Address: &quot;);\r\n  Serial.println(WiFi.localIP());\r\n\r\n  camera_config_t config;\r\n  config.ledc_channel = LEDC_CHANNEL_0;\r\n  config.ledc_timer = LEDC_TIMER_0;\r\n  config.pin_d0 = Y2_GPIO_NUM;\r\n  config.pin_d1 = Y3_GPIO_NUM;\r\n  config.pin_d2 = Y4_GPIO_NUM;\r\n  config.pin_d3 = Y5_GPIO_NUM;\r\n  config.pin_d4 = Y6_GPIO_NUM;\r\n  config.pin_d5 = Y7_GPIO_NUM;\r\n  config.pin_d6 = Y8_GPIO_NUM;\r\n  config.pin_d7 = Y9_GPIO_NUM;\r\n  config.pin_xclk = XCLK_GPIO_NUM;\r\n  config.pin_pclk = PCLK_GPIO_NUM;\r\n  config.pin_vsync = VSYNC_GPIO_NUM;\r\n  config.pin_href = HREF_GPIO_NUM;\r\n  config.pin_sccb_sda = SIOD_GPIO_NUM;\r\n  config.pin_sccb_scl = SIOC_GPIO_NUM;\r\n  config.pin_pwdn = PWDN_GPIO_NUM;\r\n  config.pin_reset = RESET_GPIO_NUM;\r\n  config.xclk_freq_hz = 20000000;\r\n  config.pixel_format = PIXFORMAT_JPEG;\r\n\r\n  \/\/ init with high specs to pre-allocate larger buffers\r\n  if(psramFound()){\r\n    config.frame_size = FRAMESIZE_SVGA;\r\n    config.jpeg_quality = 10;  \/\/0-63 lower number means higher quality\r\n    config.fb_count = 2;\r\n  } else {\r\n    config.frame_size = FRAMESIZE_CIF;\r\n    config.jpeg_quality = 12;  \/\/0-63 lower number means higher quality\r\n    config.fb_count = 1;\r\n  }\r\n  \r\n  \/\/ camera init\r\n  esp_err_t err = esp_camera_init(&amp;config);\r\n  if (err != ESP_OK) {\r\n    Serial.printf(&quot;Camera init failed with error 0x%x&quot;, err);\r\n    delay(1000);\r\n    ESP.restart();\r\n  }\r\n\r\n  sendPhoto(); \r\n}\r\n\r\nvoid loop() {\r\n  unsigned long currentMillis = millis();\r\n  if (currentMillis - previousMillis &gt;= timerInterval) {\r\n    sendPhoto();\r\n    previousMillis = currentMillis;\r\n  }\r\n}\r\n\r\nString sendPhoto() {\r\n  String getAll;\r\n  String getBody;\r\n\r\n  camera_fb_t * fb = NULL;\r\n  fb = esp_camera_fb_get();\r\n  if(!fb) {\r\n    Serial.println(&quot;Camera capture failed&quot;);\r\n    delay(1000);\r\n    ESP.restart();\r\n  }\r\n  \r\n  Serial.println(&quot;Connecting to server: &quot; + serverName);\r\n\r\n  if (client.connect(serverName.c_str(), serverPort)) {\r\n    Serial.println(&quot;Connection successful!&quot;);    \r\n    String head = &quot;--RandomNerdTutorials\\r\\nContent-Disposition: form-data; name=\\&quot;imageFile\\&quot;; filename=\\&quot;esp32-cam.jpg\\&quot;\\r\\nContent-Type: image\/jpeg\\r\\n\\r\\n&quot;;\r\n    String tail = &quot;\\r\\n--RandomNerdTutorials--\\r\\n&quot;;\r\n\r\n    uint32_t imageLen = fb-&gt;len;\r\n    uint32_t extraLen = head.length() + tail.length();\r\n    uint32_t totalLen = imageLen + extraLen;\r\n  \r\n    client.println(&quot;POST &quot; + serverPath + &quot; HTTP\/1.1&quot;);\r\n    client.println(&quot;Host: &quot; + serverName);\r\n    client.println(&quot;Content-Length: &quot; + String(totalLen));\r\n    client.println(&quot;Content-Type: multipart\/form-data; boundary=RandomNerdTutorials&quot;);\r\n    client.println();\r\n    client.print(head);\r\n  \r\n    uint8_t *fbBuf = fb-&gt;buf;\r\n    size_t fbLen = fb-&gt;len;\r\n    for (size_t n=0; n&lt;fbLen; n=n+1024) {\r\n      if (n+1024 &lt; fbLen) {\r\n        client.write(fbBuf, 1024);\r\n        fbBuf += 1024;\r\n      }\r\n      else if (fbLen%1024&gt;0) {\r\n        size_t remainder = fbLen%1024;\r\n        client.write(fbBuf, remainder);\r\n      }\r\n    }   \r\n    client.print(tail);\r\n    \r\n    esp_camera_fb_return(fb);\r\n    \r\n    int timoutTimer = 10000;\r\n    long startTimer = millis();\r\n    boolean state = false;\r\n    \r\n    while ((startTimer + timoutTimer) &gt; millis()) {\r\n      Serial.print(&quot;.&quot;);\r\n      delay(100);      \r\n      while (client.available()) {\r\n        char c = client.read();\r\n        if (c == '\\n') {\r\n          if (getAll.length()==0) { state=true; }\r\n          getAll = &quot;&quot;;\r\n        }\r\n        else if (c != '\\r') { getAll += String(c); }\r\n        if (state==true) { getBody += String(c); }\r\n        startTimer = millis();\r\n      }\r\n      if (getBody.length()&gt;0) { break; }\r\n    }\r\n    Serial.println();\r\n    client.stop();\r\n    Serial.println(getBody);\r\n  }\r\n  else {\r\n    getBody = &quot;Connection to &quot; + serverName +  &quot; failed.&quot;;\r\n    Serial.println(getBody);\r\n  }\r\n  return getBody;\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/ESP32-CAM-HTTP-POST-Image.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ESP32-CAM-HTTPS-POST-Request\">ESP32-CAM HTTPS POST Request<\/h4>\n\n\n\n<p>The next sketch posts the image to a server using HTTPS POST. Copy the code below to your Arduino IDE.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos\r\n  Complete project details at:\r\n  https:\/\/RandomNerdTutorials.com\/esp32-cam-http-post-php-arduino\/\r\n  https:\/\/RandomNerdTutorials.com\/esp32-cam-post-image-photo-server\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n*\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;WiFi.h&gt;\r\n#include &lt;WiFiClientSecure.h&gt;\r\n#include &quot;soc\/soc.h&quot;\r\n#include &quot;soc\/rtc_cntl_reg.h&quot;\r\n#include &quot;esp_camera.h&quot;\r\n\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\nString serverName = &quot;example.com&quot;;   \/\/REPLACE WITH YOUR DOMAIN NAME\r\n\r\nString serverPath = &quot;\/upload.php&quot;;     \/\/ The default serverPath should be upload.php\r\n\r\nconst int serverPort = 443; \/\/server port for HTTPS\r\n\r\nWiFiClientSecure client;\r\n\r\n\/\/ CAMERA_MODEL_AI_THINKER\r\n#define PWDN_GPIO_NUM     32\r\n#define RESET_GPIO_NUM    -1\r\n#define XCLK_GPIO_NUM      0\r\n#define SIOD_GPIO_NUM     26\r\n#define SIOC_GPIO_NUM     27\r\n\r\n#define Y9_GPIO_NUM       35\r\n#define Y8_GPIO_NUM       34\r\n#define Y7_GPIO_NUM       39\r\n#define Y6_GPIO_NUM       36\r\n#define Y5_GPIO_NUM       21\r\n#define Y4_GPIO_NUM       19\r\n#define Y3_GPIO_NUM       18\r\n#define Y2_GPIO_NUM        5\r\n#define VSYNC_GPIO_NUM    25\r\n#define HREF_GPIO_NUM     23\r\n#define PCLK_GPIO_NUM     22\r\n\r\nconst int timerInterval = 30000;    \/\/ time between each HTTP POST image\r\nunsigned long previousMillis = 0;   \/\/ last time image was sent\r\n\r\nvoid setup() {\r\n  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); \r\n  Serial.begin(115200);\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  Serial.println();\r\n  Serial.print(&quot;Connecting to &quot;);\r\n  Serial.println(ssid);\r\n  WiFi.begin(ssid, password);  \r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print(&quot;.&quot;);\r\n    delay(500);\r\n  }\r\n  Serial.println();\r\n  Serial.print(&quot;ESP32-CAM IP Address: &quot;);\r\n  Serial.println(WiFi.localIP());\r\n\r\n  camera_config_t config;\r\n  config.ledc_channel = LEDC_CHANNEL_0;\r\n  config.ledc_timer = LEDC_TIMER_0;\r\n  config.pin_d0 = Y2_GPIO_NUM;\r\n  config.pin_d1 = Y3_GPIO_NUM;\r\n  config.pin_d2 = Y4_GPIO_NUM;\r\n  config.pin_d3 = Y5_GPIO_NUM;\r\n  config.pin_d4 = Y6_GPIO_NUM;\r\n  config.pin_d5 = Y7_GPIO_NUM;\r\n  config.pin_d6 = Y8_GPIO_NUM;\r\n  config.pin_d7 = Y9_GPIO_NUM;\r\n  config.pin_xclk = XCLK_GPIO_NUM;\r\n  config.pin_pclk = PCLK_GPIO_NUM;\r\n  config.pin_vsync = VSYNC_GPIO_NUM;\r\n  config.pin_href = HREF_GPIO_NUM;\r\n  config.pin_sccb_sda = SIOD_GPIO_NUM;\r\n  config.pin_sccb_scl = SIOC_GPIO_NUM;\r\n  config.pin_pwdn = PWDN_GPIO_NUM;\r\n  config.pin_reset = RESET_GPIO_NUM;\r\n  config.xclk_freq_hz = 20000000;\r\n  config.pixel_format = PIXFORMAT_JPEG;\r\n\r\n  \/\/ init with high specs to pre-allocate larger buffers\r\n  if(psramFound()){\r\n    config.frame_size = FRAMESIZE_SVGA;\r\n    config.jpeg_quality = 10;  \/\/0-63 lower number means higher quality\r\n    config.fb_count = 2;\r\n  } else {\r\n    config.frame_size = FRAMESIZE_CIF;\r\n    config.jpeg_quality = 12;  \/\/0-63 lower number means higher quality\r\n    config.fb_count = 1;\r\n  }\r\n  \r\n  \/\/ camera init\r\n  esp_err_t err = esp_camera_init(&amp;config);\r\n  if (err != ESP_OK) {\r\n    Serial.printf(&quot;Camera init failed with error 0x%x&quot;, err);\r\n    delay(1000);\r\n    ESP.restart();\r\n  }\r\n\r\n  sendPhoto(); \r\n}\r\n\r\nvoid loop() {\r\n  unsigned long currentMillis = millis();\r\n  if (currentMillis - previousMillis &gt;= timerInterval) {\r\n    sendPhoto();\r\n    previousMillis = currentMillis;\r\n  }\r\n}\r\n\r\nString sendPhoto() {\r\n  String getAll;\r\n  String getBody;\r\n\r\n  camera_fb_t * fb = NULL;\r\n  fb = esp_camera_fb_get();\r\n  if(!fb) {\r\n    Serial.println(&quot;Camera capture failed&quot;);\r\n    delay(1000);\r\n    ESP.restart();\r\n  }\r\n  \r\n  Serial.println(&quot;Connecting to server: &quot; + serverName);\r\n  \r\n  client.setInsecure(); \/\/skip certificate validation\r\n  if (client.connect(serverName.c_str(), serverPort)) {\r\n    Serial.println(&quot;Connection successful!&quot;);    \r\n    String head = &quot;--RandomNerdTutorials\\r\\nContent-Disposition: form-data; name=\\&quot;imageFile\\&quot;; filename=\\&quot;esp32-cam.jpg\\&quot;\\r\\nContent-Type: image\/jpeg\\r\\n\\r\\n&quot;;\r\n    String tail = &quot;\\r\\n--RandomNerdTutorials--\\r\\n&quot;;\r\n\r\n    uint32_t imageLen = fb-&gt;len;\r\n    uint32_t extraLen = head.length() + tail.length();\r\n    uint32_t totalLen = imageLen + extraLen;\r\n  \r\n    client.println(&quot;POST &quot; + serverPath + &quot; HTTP\/1.1&quot;);\r\n    client.println(&quot;Host: &quot; + serverName);\r\n    client.println(&quot;Content-Length: &quot; + String(totalLen));\r\n    client.println(&quot;Content-Type: multipart\/form-data; boundary=RandomNerdTutorials&quot;);\r\n    client.println();\r\n    client.print(head);\r\n  \r\n    uint8_t *fbBuf = fb-&gt;buf;\r\n    size_t fbLen = fb-&gt;len;\r\n    for (size_t n=0; n&lt;fbLen; n=n+1024) {\r\n      if (n+1024 &lt; fbLen) {\r\n        client.write(fbBuf, 1024);\r\n        fbBuf += 1024;\r\n      }\r\n      else if (fbLen%1024&gt;0) {\r\n        size_t remainder = fbLen%1024;\r\n        client.write(fbBuf, remainder);\r\n      }\r\n    }   \r\n    client.print(tail);\r\n    \r\n    esp_camera_fb_return(fb);\r\n    \r\n    int timoutTimer = 10000;\r\n    long startTimer = millis();\r\n    boolean state = false;\r\n    \r\n    while ((startTimer + timoutTimer) &gt; millis()) {\r\n      Serial.print(&quot;.&quot;);\r\n      delay(100);      \r\n      while (client.available()) {\r\n        char c = client.read();\r\n        if (c == '\\n') {\r\n          if (getAll.length()==0) { state=true; }\r\n          getAll = &quot;&quot;;\r\n        }\r\n        else if (c != '\\r') { getAll += String(c); }\r\n        if (state==true) { getBody += String(c); }\r\n        startTimer = millis();\r\n      }\r\n      if (getBody.length()&gt;0) { break; }\r\n    }\r\n    Serial.println();\r\n    client.stop();\r\n    Serial.println(getBody);\r\n  }\r\n  else {\r\n    getBody = &quot;Connection to &quot; + serverName +  &quot; failed.&quot;;\r\n    Serial.println(getBody);\r\n  }\r\n  return getBody;\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/ESP32-CAM-Arduino-IDE\/raw\/master\/ESP32-CAM-HTTP-POST-Image\/ESP32-CAM-HTTPS-POST-Image.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p class=\"rntbox rntclblue\">Learn more about HTTPS Requests with the ESP32: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-https-requests\/\">ESP32 HTTPS Requests (Arduino IDE)<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Inserting your Network Credentials, Camera, and Server Details<\/h4>\n\n\n\n<p>Before uploading the code, you need to insert your network credentials in the following variables:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Make sure you select the right camera module. In this case, we\u2019re using the AI-THINKER Model. If you&#8217;re using another camera model, you can read this <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-camera-pin-gpios\/\">Guide ESP32-CAM Camera Boards: Pin and GPIOs Assignment<\/a>.<\/p>\n\n\n\n<p>Add your Raspberry Pi IP address or use the server domain name:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String serverName = \"192.168.1.XXX\";   \/\/ REPLACE WITH YOUR Raspberry Pi IP ADDRESS\n\/\/String serverName = \"example.com\";   \/\/ OR REPLACE WITH YOUR DOMAIN NAME\nString serverPath = \"\/upload.php\";     \/\/ The default serverPath should be upload.php<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Upload Code to ESP32-CAM<\/h3>\n\n\n\n<p>Now you can upload the code to your ESP32-CAM board. Connect the ESP32-CAM board to your computer using an <a rel=\"noreferrer noopener\" aria-label=\"FTDI programmer (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\">FTDI programmer<\/a>. <\/p>\n\n\n\n<p>Follow the next schematic diagram:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"532\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-CAM-FTDI-programmer.png?resize=877%2C532&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM connected to an FTDI Programmer to upload program using Arduino IDE\" class=\"wp-image-159060\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-CAM-FTDI-programmer.png?w=877&amp;quality=100&amp;strip=all&amp;ssl=1 877w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-CAM-FTDI-programmer.png?resize=300%2C182&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/06\/ESP32-CAM-FTDI-programmer.png?resize=768%2C466&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/figure><\/div>\n\n\n<p>Many FTDI programmers have a jumper that allows you to select 3.3V or 5V. Make sure the jumper is in the right place to select 5V.<\/p>\n\n\n\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> <span class=\"rnthl rntclgray\">GPIO 0<\/span> needs to be connected to <span class=\"rnthl rntcblack\">GND<\/span> so that you\u2019re able to upload code.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>ESP32-CAM<\/strong><\/td><td><strong>FTDI Programmer<\/strong><\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><tr><td>5V<\/td><td>VCC (5V)<\/td><\/tr><tr><td>U0R<\/td><td>TX<\/td><\/tr><tr><td>U0T<\/td><td>RX<\/td><\/tr><tr><td>GPIO 0<\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To upload the code, follow the next steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <strong>Tools <\/strong>&gt; <strong>Board <\/strong>and select <strong>AI-Thinker ESP32-CAM<\/strong>.<\/li>\n\n\n\n<li>Go to <strong>Tools <\/strong>&gt; <strong>Port <\/strong>and select the COM port the ESP32 is connected to.<\/li>\n\n\n\n<li>Then, click the upload button to upload the code.<\/li>\n\n\n\n<li>When you start to see these dots on the debugging window as shown below, press the ESP32-CAM on-board RST button.   <\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1009\" height=\"91\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/12\/dots-uploading-code.png?resize=1009%2C91&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM camera board upload new Arduino IDE sketch press RESET button\" class=\"wp-image-91746\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/12\/dots-uploading-code.png?w=1009&amp;quality=100&amp;strip=all&amp;ssl=1 1009w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/12\/dots-uploading-code.png?resize=300%2C27&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/12\/dots-uploading-code.png?resize=768%2C69&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1009px) 100vw, 1009px\" \/><\/figure><\/div>\n\n\n<p>After a few seconds, the code should be successfully uploaded to your board.<\/p>\n\n\n\n<p>If you have troubles uploading the code, read our <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-troubleshooting-guide\/\">ESP32-CAM Troubleshooting Guide<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Here&#8217;s a quick explanation of how the code works:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Imports all libraries;<\/li>\n\n\n\n<li>Defines the needed variables;<\/li>\n\n\n\n<li>Defines the camera pins;<\/li>\n\n\n\n<li>In the <span class=\"rnthl rntliteral\">setup()<\/span> you establish a Wi-Fi connection and initialize the ESP32 camera. <\/li>\n\n\n\n<li>The <span class=\"rnthl rntliteral\">loop()<\/span> has a <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pir-motion-sensor-interrupts-timers\/\">timer<\/a> that calls the <span class=\"rnthl rntliteral\">sendPhoto()<\/span> function every 30 seconds. You can change that delay time in the <span class=\"rnthl rntliteral\">timerInterval<\/span> variable.<\/li>\n<\/ul>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">sendPhoto()<\/span> function is the part that actually takes a photo and sends it to your server. You can use that function in other of your projects that require taking and publishing a photo to a server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4\">4. Testing and Final Demonstration<\/h2>\n\n\n\n<p>After uploading the code to your board, open the Arduino IDE Serial Monitor and you should see a similar message being printed every 30 seconds:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The file esp32-cam.jpg has been uploaded.<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"492\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-esp32-cam-jpg-file-Arduino-IDE-Serial-Monitor.png?resize=767%2C492&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM file esp32-cam.jpg has been uploaded Arduino IDE Serial Monitor testing project\" class=\"wp-image-97912\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-esp32-cam-jpg-file-Arduino-IDE-Serial-Monitor.png?w=767&amp;quality=100&amp;strip=all&amp;ssl=1 767w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-esp32-cam-jpg-file-Arduino-IDE-Serial-Monitor.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/figure><\/div>\n\n\n<p>If you go to your local server URL <em>http:\/\/IP-Address\/uploads<\/em>, or to your cloud server URL <em>https:\/\/example.com\/uploads<\/em> you should have a folder with all your stored photos.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"496\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Uploads-Folder-Images-stored-server.png?resize=691%2C496&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Board Uploads Folder Images stored server Demonstration\" class=\"wp-image-97909\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Uploads-Folder-Images-stored-server.png?w=691&amp;quality=100&amp;strip=all&amp;ssl=1 691w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Board-Uploads-Folder-Images-stored-server.png?resize=300%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><\/figure><\/div>\n\n\n<p>You can open each link to open a new page with the full image:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1113\" height=\"714\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Upload-Photo-to-Server-PHP-Arduino-IDE.jpg?resize=1113%2C714&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Upload Photo or Image to Server PHP Arduino IDE\" class=\"wp-image-97917\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Upload-Photo-to-Server-PHP-Arduino-IDE.jpg?w=1113&amp;quality=100&amp;strip=all&amp;ssl=1 1113w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Upload-Photo-to-Server-PHP-Arduino-IDE.jpg?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Upload-Photo-to-Server-PHP-Arduino-IDE.jpg?resize=1024%2C657&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Upload-Photo-to-Server-PHP-Arduino-IDE.jpg?resize=768%2C493&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1113px) 100vw, 1113px\" \/><\/figure><\/div>\n\n\n<p>Now, if you go to your local server URL <em>http:\/\/IP-Address\/gallery.php<\/em>, or to your cloud server URL <em>https:\/\/example.com\/gallery.php,<\/em> you can access the gallery page, where you can view and delete the photos.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"634\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Photo-Gallery-view-PHP-f.jpg?resize=900%2C634&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Camera Photo Gallery view PHP file\" class=\"wp-image-97936\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Photo-Gallery-view-PHP-f.jpg?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Photo-Gallery-view-PHP-f.jpg?resize=300%2C211&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-Camera-Photo-Gallery-view-PHP-f.jpg?resize=768%2C541&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<p>To delete any photo, just click on the &#8220;Delete file&#8221; link next to each image.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"918\" height=\"519\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-delete-file-from-gallery-php.jpg?resize=918%2C519&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM delete file from gallery php\" class=\"wp-image-97937\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-delete-file-from-gallery-php.jpg?w=918&amp;quality=100&amp;strip=all&amp;ssl=1 918w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-delete-file-from-gallery-php.jpg?resize=300%2C170&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/06\/ESP32-CAM-delete-file-from-gallery-php.jpg?resize=768%2C434&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 918px) 100vw, 918px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>That&#8217;s it! Now, you can send your ESP32-CAM photos to any server using HTTP POST. Modify this project to best suit your needs. For example, take a photo and send to a server when motion is detected.<\/p>\n\n\n\n<p>Other ESP32 tutorials you might be interested in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-http-get-post-arduino\/\">ESP32 HTTP GET and HTTP POST<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-http-get-open-weather-map-thingspeak-arduino\/\">ESP32 HTTP GET Web APIs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-http-post-ifttt-thingspeak-arduino\/\">ESP32 HTTP POST Web APIs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-https-requests\/\">ESP32 HTTPS Requests (Arduino IDE)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the ESP32-CAM:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-projects-ebook\/\">Build ESP32-CAM Projects using Arduino IDE eBook<\/a><\/strong><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32-cam\/\">More ESP32-CAM projects &#8230;<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to make HTTP POST requests using the ESP32-CAM board with Arduino IDE to send photos to a server. We\u2019ll show how to post a JPG\/JPEG image to a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32-CAM Post Images to Local or Cloud Server using PHP (Photo Manager)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-post-image-photo-server\/#more-97893\" aria-label=\"Read more about ESP32-CAM Post Images to Local or Cloud Server using PHP (Photo Manager)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":129728,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,319,264],"tags":[],"class_list":["post-97893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-cam","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/ESP32-CAM-Cloud-Photo-Manager-f.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/97893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=97893"}],"version-history":[{"count":10,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/97893\/revisions"}],"predecessor-version":[{"id":159107,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/97893\/revisions\/159107"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/129728"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=97893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=97893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=97893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}