You should use the _FILES super global to access binary uploaded files from a temporary directory on the server
OR
encode the binary data as Base64 (or some other text only encoding) for use in the _POST variable.
See http://php.net/manual/en/features.file-upload.php
To have the file appear in _FILES modify the doc example:
QHttpPart imagePart;
imagePart.
setHeader(QNetworkRequest
::ContentTypeHeader,
QVariant("image/jpeg"));
imagePart.
setHeader(QNetworkRequest
::ContentDispositionHeader,
QVariant("form-data; name=\"image\"; filename=\"image.jpg\""));
// <<< filename triggers separate handlingimagePart.setBodyDevice(file);
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"; filename=\"image.jpg\"")); // <<< filename triggers separate handling
QFile *file = new QFile("image.jpg");
file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
To copy to clipboard, switch view to plain text mode
and then you will see in the PHP environment:
chrisw@newton /tmp/simple_example $ ./simple_example
// _POST array
array(1) {
["text"]=>
string(7) "my text"
}
// _FILES array
array(1) {
["image"]=>
array(5) {
["name"]=>
string(9) "image.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpaLYWWk"
["error"]=>
int(0)
["size"]=>
int(16246)
}
}
chrisw@newton /tmp/simple_example $ ./simple_example
// _POST array
array(1) {
["text"]=>
string(7) "my text"
}
// _FILES array
array(1) {
["image"]=>
array(5) {
["name"]=>
string(9) "image.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpaLYWWk"
["error"]=>
int(0)
["size"]=>
int(16246)
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks