我想从php脚本下载* .exe文件并执行它。使用C++和Qt下载二进制文件
当我下载文件后,我可以'执行它了。当我查看文件时,其中有很多问号。
PHP脚本:
header('Content-Description: File Transfer');
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename='.basename($file_name));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file_name));
ob_clean();
flush();
readfile($file_name);
exit;
C++:
QFile offline_ip_adress_calculator(QDir::currentPath() + "/offline_ip_adress_calculator.exe");
//Check if the File exists and clear its content
if(!offline_ip_adress_calculator.open(QFile::ReadWrite | QIODevice::Truncate))
{
msgBox.critical(this, "I/O error", "Can't open offline_ip_adress_calculator.exe for update");
return;
}
QDataStream text_stream(&offline_ip_adress_calculator);
while(reply->size() > 0)
{
QByteArray replystring = reply->read(2048);
text_stream << replystring;
}
offline_ip_adress_calculator.close();
的答复是 “QNetworkReply”
哇,太简单了。它的工作原理:) – user2357505
你是如何选择缓冲区为2048?如果文件大于2018字节会发生什么情况? –
@MuhammetAliAsan 2048在计算机方面是一个不错的数字(2的倍数)。如果有更多的数据要读取,它只需要两个(或更多)迭代来读取/写入所有数据。 –