Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ESP32尝试使用HTTPClient将图像文件发送到php_Php_C_Http_Arduino_Esp32 - Fatal编程技术网

ESP32尝试使用HTTPClient将图像文件发送到php

ESP32尝试使用HTTPClient将图像文件发送到php,php,c,http,arduino,esp32,Php,C,Http,Arduino,Esp32,我在尝试在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=\"pict

我在尝试在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();
注意:第23行C:\xampp\htdocs\acc.php中的未定义索引:imageFile

我在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();
我可以使用此代码发送字符串,但上面的代码不起作用 (cam.getfb()返回为uint8\u t,cam.getSize()返回为size\u t)

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.";
    }
}
?>
和php

<?php
$uploadfile = "";
echo "Uploading ";
echo $_FILES["imageFile"]["name"];
if(strlen(basename($_FILES["imageFile"]["name"])) > 0)
{
 $uploadfile = basename($_FILES["imageFile"]["name"]);
 if(move_uploaded_file($_FILES["imageFile"]["tmp_name"], $uploadfile))
 {
 @chmod($uploadfile,0777); echo " Ok! ";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
if (file_exists("old/".date('Y_m_d', $datum) )) {
 print("Directory already exists.\n");
 } else {
 mkdir("old/".date('Y_m_d', $datum));
 copy("index1.php","old/".date('Y_m_d', $datum)."/index.php");
 print("Directory creating.\n");
 }
echo "saved ";
copy($uploadfile,"old/".date('Y_m_d', $datum)."/".date('Y.m.d_H-i-s', $datum).".jpg");
 }
 else echo " Error copying!";
}
echo date('Y.m.d_H:i', $datum);
echo "status = DONE";
?>
<?php
$uploadfile = "";
echo "Uploading ";
echo $_FILES["imageFile"]["name"];
if(strlen(basename($_FILES["imageFile"]["name"])) > 0)
{
 $uploadfile = basename($_FILES["imageFile"]["name"]);
 if(move_uploaded_file($_FILES["imageFile"]["tmp_name"], $uploadfile))
 {
 @chmod($uploadfile,0777); echo " Ok! ";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
if (file_exists("old/".date('Y_m_d', $datum) )) {
 print("Directory already exists.\n");
 } else {
 mkdir("old/".date('Y_m_d', $datum));
 copy("index1.php","old/".date('Y_m_d', $datum)."/index.php");
 print("Directory creating.\n");
 }
echo "saved ";
copy($uploadfile,"old/".date('Y_m_d', $datum)."/".date('Y.m.d_H-i-s', $datum).".jpg");
 }
 else echo " Error copying!";
}
echo date('Y.m.d_H:i', $datum);
echo "status = DONE";
?>

工作

和php

<?php
$uploadfile = "";
echo "Uploading ";
echo $_FILES["imageFile"]["name"];
if(strlen(basename($_FILES["imageFile"]["name"])) > 0)
{
 $uploadfile = basename($_FILES["imageFile"]["name"]);
 if(move_uploaded_file($_FILES["imageFile"]["tmp_name"], $uploadfile))
 {
 @chmod($uploadfile,0777); echo " Ok! ";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
if (file_exists("old/".date('Y_m_d', $datum) )) {
 print("Directory already exists.\n");
 } else {
 mkdir("old/".date('Y_m_d', $datum));
 copy("index1.php","old/".date('Y_m_d', $datum)."/index.php");
 print("Directory creating.\n");
 }
echo "saved ";
copy($uploadfile,"old/".date('Y_m_d', $datum)."/".date('Y.m.d_H-i-s', $datum).".jpg");
 }
 else echo " Error copying!";
}
echo date('Y.m.d_H:i', $datum);
echo "status = DONE";
?>
<?php
$uploadfile = "";
echo "Uploading ";
echo $_FILES["imageFile"]["name"];
if(strlen(basename($_FILES["imageFile"]["name"])) > 0)
{
 $uploadfile = basename($_FILES["imageFile"]["name"]);
 if(move_uploaded_file($_FILES["imageFile"]["tmp_name"], $uploadfile))
 {
 @chmod($uploadfile,0777); echo " Ok! ";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
if (file_exists("old/".date('Y_m_d', $datum) )) {
 print("Directory already exists.\n");
 } else {
 mkdir("old/".date('Y_m_d', $datum));
 copy("index1.php","old/".date('Y_m_d', $datum)."/index.php");
 print("Directory creating.\n");
 }
echo "saved ";
copy($uploadfile,"old/".date('Y_m_d', $datum)."/".date('Y.m.d_H-i-s', $datum).".jpg");
 }
 else echo " Error copying!";
}
echo date('Y.m.d_H:i', $datum);
echo "status = DONE";
?>


不能只将单个表单元素作为有效负载。您首先需要
内容类型:多部分/表单数据。然后嵌入图像条目。否则PHP将不会填充
$\u文件
/或者,您可以通过
php://input
当然可以,但不会有任何有效负载元信息(
$\u文件
)。请将您的解决方案移动到自己的答案,谢谢。您好,是否可以将MJPEG流从摄像头发送到PHP服务器,并直接记录在服务器上?
<?php
$uploadfile = "";
echo "Uploading ";
echo $_FILES["imageFile"]["name"];
if(strlen(basename($_FILES["imageFile"]["name"])) > 0)
{
 $uploadfile = basename($_FILES["imageFile"]["name"]);
 if(move_uploaded_file($_FILES["imageFile"]["tmp_name"], $uploadfile))
 {
 @chmod($uploadfile,0777); echo " Ok! ";
$datum = mktime(date('H')+0, date('i'), date('s'), date('m'), date('d'), date('y'));
if (file_exists("old/".date('Y_m_d', $datum) )) {
 print("Directory already exists.\n");
 } else {
 mkdir("old/".date('Y_m_d', $datum));
 copy("index1.php","old/".date('Y_m_d', $datum)."/index.php");
 print("Directory creating.\n");
 }
echo "saved ";
copy($uploadfile,"old/".date('Y_m_d', $datum)."/".date('Y.m.d_H-i-s', $datum).".jpg");
 }
 else echo " Error copying!";
}
echo date('Y.m.d_H:i', $datum);
echo "status = DONE";
?>