C ++ Qt sends a POST file stream to the PHP interface,

Source: Internet
Author: User

C ++ Qt sends a POST file stream to the PHP interface,

Qt calls the PHP-written interface, transmits the image file to it, and stores the file on the server.

Binary files cannot be directly transmitted. Qt uses Base64 for encoding, and PHP decoding is saved as files.

Note: After receiving the data, PHP will replace the plus sign (+) in the POST data with a space, resulting in incomplete received data and failure to restore the data normally, in this example, all spaces are replaced with the + sign before PHP decoding.

Qt file:

// Qt file QFile file ("1.jpg"); if (! File. open (QIODevice: ReadOnly) {qDebug () <"file open failed. "; return;} QByteArray data = file. readAll (); file. close (); QNetworkRequest req (QUrl ("http: // localhost: 88/index. php "); networkMgr-> post (req," fileData = "+ data. toBase64 () + "");

PHP file:

<? Php $ recContent = $ _ POST ['filedata']; $ data = base64_decode (str_replace ("", "+", ($ recContent); file_put_contents ("1.jpg ", $ data);?>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.