Przy uruchamianiu pliku upload.exe cały czas otrzymuję komunikat please select a file zapewne nie otrzymuje POST jako upload $_FILES['upload'] tylko nie wiem jak to zrobić w C++
Plik upload.cpp
#include <winsock2.h>
#include <windows.h>
#include <iostream>
using namespace std;
int main (){
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
cout << "WSAStartup failed.\n";
return 1;
}
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
struct hostent *host;
host = gethostbyname("localhost");
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(80);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
cout << "Connecting...\n";
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0){
cout << "Could not connect";
return 1;
}
cout << "Connected.\n";
char *header="POST /upload.php HTTP/1.1\r\n"
"Host: localhost\r\n"
"Content-Type: multipart/form-data; boundary=myboundary\r\n"
"Connection: close\r\n"
"\r\n"
"--myboundary\r\n"
"Content-Type: application/octet-stream\r\n"
"Content-Disposition: form-data; name=\"file\"; filename=\"C:\\Users\\User\\Downloads\\file.txt\"\r\n"
"Content-Transfer-Encoding: 8bit\r\n"
"\r\n";
send(Socket,header, strlen(header),0);
char buffer[100000];
int nDataLength;
while ((nDataLength = recv(Socket,buffer,100000,0)) > 0){
int i = 0;
while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
cout << buffer[i];
i += 1;
}
}
closesocket(Socket);
WSACleanup();
return 0;
}
Plik upload.php
<?php
$uploaddir = '/upload';
$uploadfile = $uploaddir . basename($_FILES['upload']['name']);
if(!isset($_FILES['upload'])) {
echo "Please select a file\n";
} else {
if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $uploadFile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
}
?>