C + + needs to implement the PHP side:
Bin2Hex
function, PHP is called by this type of string:
Pack
Translates to 2 of binary data that PHP can recognize.
C + + needs to do is to implement a bin2hex, in fact, the C + + read 2 binary data as a byte array, each bit into a 16 binary string. The use of sprintf in QT cannot limit the 2-bit length, so after sprintf, the length is 8 to intercept the last 3 strings, including the/0 terminator
QString Bin2Hex (char* data1,intLen) {QStrings; QString R; for(intx=0;x
x + +)
{
s .
sprintf (
"%02x +" , data1[
x ]);
if
(
s .
length () >
2 ) {
s =
s . Mid (
6 ,
8 ); } r.append (
s ); }
return R;
Qvariant qmlclass::readimg (QString file) {QFile mfile (file);
if
(!mfile.
Open (qiodevice::readonly))
{qdebug () <<
"file does not exist" ;
return
"" ; } qdebug () <<
"file exists" ; Qbytearray ar = Mfile.readall (); char * ADR =ar.data ();
QString
m = Bin2Hex (Adr,ar.size ());
return
m ;}
function uploadimg () { var x = New XMLHttpRequest (); X.onreadystatechange = function () { if (x.readystate = = 4 ) { if (x.status = = + ) {Console.log () the server R Eplied with: " + x.responsetext); Txt.text = X.responsetext; } } }; var xxx = new Object ; var d=myapp.readimg ( ":/1.jpg" ); Console.log ( typeof D) x.open ( "POST" , "http://localhost/mycode/Test/reg.php" , true ); Console.log (d) //post request to set the request header X.setrequestheader ( "Content-type" , "Applicat Ion/x-www-form-urlencoded "); X.send (d); }
$filename="teststream.jpg";//要生成的图片名字 $data_buff=file_get_contents("php://input"); echo$data_buff; $jpg = pack("H*",$data_buff);//得到post过来的二进制原始数据 $file = fopen("pic/".$filename,"wb");//打开文件准备写入 fwrite($file,$jpg);//写入 fclose($file);//关闭?>
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the introduction of PHP 5 C + + and PHP binary transmission, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.