I got this after I try to running my code on esp32
Notice: Undefined index: imageFile in C:\xampp\htdocs\acc.php on line 23
My code on esp32
HTTPClient http;
http.begin("http://192.168.43.86/acc.php"); //Specify destination for HTTP request
http.addHeader("Content-Disposition", "form-data; name=\"imageFile\"; filename=\"picture.jpg\"\r\n");
http.addHeader("Content-type", "image/jpeg");
int httpResponseCode = http.POST(cam.getfb(), cam.getSize());
if (httpResponseCode > 0) {
String response = http.getString(); //Get the response to the request
Serial.println(httpResponseCode); //Print return code
Serial.println(response); //Print request answer
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
I can send String by using this code but my code above don't work (cam.getfb() return as uint8_t and cam.getSize() return as size_t)
http.addHeader("Content-type", "application/x-www-form-urlencoded");
int httpResponseCode = http.POST("word=" + Cword);
code in php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["imageFile"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(1) {
$check = getimagesize($_FILES["imageFile"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["imageFile"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["imageFile"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["imageFile"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
11/13/2018 I try to update my code
<?php
date_default_timezone_set("Asia/Bangkok");
$date = date("Y_m_d_h_i_s");
$directory = "http://192.168.43.192/capture.jpg";
$data = $rawData = file_get_contents("php://input");
$new = "images/".$date.".jpg";
file_put_contents($new, $data);
?>