Hi everyone,

I'm trying to upload a file using ost request and a PHP script but i'm having some problems.
My file isn't uploaded to the server ($_FILES always empty even if my php script is working, validated with an HTML form).
Bytes seem to be transfered but nothing in $_FILES.

I spent a lot of time wondering why and trying all examples given on the web, so if someone can help me...

Here is my code :

Qt Code:
  1. QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
  2.  
  3. QHttpPart textPart;
  4. textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""));
  5. textPart.setBody("my text");
  6.  
  7. QHttpPart imagePart;
  8. imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
  9. imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\""));
  10. QFile *file = new QFile("C:/..../test.jpg");
  11. file->open(QIODevice::ReadOnly);
  12. imagePart.setBodyDevice(file);
  13. file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
  14.  
  15. multiPart->append(textPart);
  16. multiPart->append(imagePart);
  17.  
  18. QUrl url("http://..../test.php");
  19. QNetworkRequest request(url);
  20.  
  21. QNetworkAccessManager * manager = new QNetworkAccessManager();
  22. reply = manager->post(request, multiPart);
  23. multiPart->setParent(reply); // delete the multiPart with the reply
  24.  
  25.  
  26. connect(reply, SIGNAL( uploadProgress(qint64, qint64) ), this, SLOT( uploadProgress(qint64,qint64) ) ) ;
  27.  
  28. connect(reply, SIGNAL(finished()), this, SLOT(uploadDone()));
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
  2. qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
  3. }
  4.  
  5. void uploadDone() {
  6. qDebug() << "Finished" << reply->errorString() <<reply->attribute( QNetworkRequest::HttpStatusCodeAttribute).toInt();
  7. qDebug()<<reply->readAll();
  8.  
  9. //reply->deleteLater();
  10. }
To copy to clipboard, switch view to plain text mode 

And my ouput :

Qt Code:
  1. Uploaded 16384 of 66201
  2. Uploaded 66201 of 66201
  3. Uploaded 0 of 0
  4. Finished "Unknown error" 200
  5. "$_FILES: Array
  6. (
  7. )
To copy to clipboard, switch view to plain text mode 

Maybe the "Uploaded 0 of 0"...

Any help would be appreciated!

Thanking you in advance

Marty