web端:
<?php $c = $GLOBALS['HTTP_RAW_POST_DATA']; $n = $_GET["filename"]; $fp = fopen($n,'w+'); fwrite($fp, $c, strlen($c)); fclose($fp); ?>
QT端:
.h文件:
private: QNetworkAccessManager *_uploadManager; QNetworkReply *_reply; char* m_buf; private slots: void replyFinished( QNetworkReply* ); void upLoadError(QNetworkReply::NetworkError errorCode); void OnUploadProgress( qint64 bytesSent, qint64 bytesTotal );
.cpp文件:
_uploadManager = new QNetworkAccessManager(this); connect(_uploadManager,SIGNAL(finished(QNetworkReply*)),SLOT(replyFinished(QNetworkReply*))); m_buf = NULL; QFile file("d:/a.jpg"); file.open(QIODevice::ReadOnly); int file_len = file.size(); QDataStream in(&file); m_buf = new char[file_len]; in.readRawData( m_buf, file_len); file.close(); QNetworkRequest request(QUrl(tr(http://localhost/up.php?act=up&filename=a.jpg))); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream"); QByteArray arr = QByteArray(m_buf, file_len); _reply = _uploadManager->post(request , arr); connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(upLoadError(QNetworkReply::NetworkError))); connect(_reply, SIGNAL(uploadProgress ( qint64 ,qint64 )), this, SLOT( OnUploadProgress(qint64 ,qint64 )));
时间: 2024-09-20 00:23:53