Я пытаюсь загрузить файл «.txt» из Ubuntu Linux на сервер Apache http, используя libcurl.
Я написал приведенный ниже код c в системе Linux, чтобы выполнить отправку http-сообщения на мой сервер
#include <stdio.h>
#include <curl/curl.h>
#include <sys/stat.h>
int main(void)
{
CURL *curl;
CURLcode res;
FILE *fd;
struct stat file_info;
fd = fopen("/home/shantanu/test.txt", "rb"); /* open file to upload */
if(!fd)
return 1; /* can't continue */
/* In windows, this will init the winsock stuff */
/* to get the file size */
if(fstat(fileno(fd), &file_info) != 0)
return 1; /* can't continue */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://x.x.x.x/dashboard/");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,(curl_off_t)file_info.st_size);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,fd);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
=============================================
на стороне сервера внутри папки панели инструментов у меня есть файл с именем index.php, который имеет код ниже для перемещения файла в папку
<?PHP
move_uploaded_file($_FILE['content']['tmp_name'], "test.txt");
?>
=============================================== ==================
Но файл не загружается, и я получаю следующее o / p
* Trying 1x.6x.32.157...
* Connected to 1x.6x.32.157 (1x.6x.32.157) port 80 (#0)
> POST /dashboard/ HTTP/1.1
Host: 1x.6x.32.157
Accept: */*
Content-Length: 2487
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Date: Fri, 11 May 2018 10:32:20 GMT
< Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0g PHP/7.2.4
< X-Powered-By: PHP/7.2.4
< Content-Length: 117
< Content-Type: text/html; charset=UTF-8
<
<br />
<b>Notice</b>: Undefined index: content in <b>C:\xampp\htdocs\dashboard\index.php</b> on line <b>2</b><br />