Getting Started with PHP 5 C + + and PHP binary transfer

Source: Internet
Author: User
Tags getting started with php sprintf
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.

  • 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.