[PHP as the iOS backend JSON format HTTP communication and file upload implementation]

Source: Internet
Author: User

1. Database Connection configmysql.php

<? PHP     $q mysql_connect ("localhost:8889", "root", "root");     if (! $q )    {       diemysql_error());    }     mysql_query // read Data//mysql_select_db with UTF8    ("MyDB", $q);//Select Database ?>

2.POST or GET request, JSON returns selectuser.php

<?include("configmysql.php"); mysql_select_db("MyDB",$q);//Select the database//get or post parameters or    $TEMPid=$_get[' UserID ']; //$TEMPid =$_post[' userid '];    $sql= "SELECT * from USERINFOTB where userid=".$TEMPid; $query=mysql_query($sql) or die(Mysql_error());  while($row=Mysql_fetch_array($query)){        $json=$row; }    EchoJson_encode ($json);?>

3. Multiple sets of data selectuser.php

<?include("configmysql.php"); mysql_select_db("Chepaidb",$q);//Database    $TEMPid=$_get[' DriverID ']; $sql= "SELECT * from Driverinfo where driverid=".$TEMPid; $query=mysql_query($sql) or die(Mysql_error());  while($row=Mysql_fetch_array($query)){        $json 1=$row; }        $sql 2= "SELECT * from Driverillegalinfo where idriverid=".$TEMPid. "ORDER BY Iid Desc"; $query 2=mysql_query($sql 2) or die(Mysql_error()); $json 2=Array(); $sum=0;  while($row 2=Mysql_fetch_array($query 2)){        $json 2[' Row '.$sum] =$row 2; $sum++; }    $newJson=Json_encode (Array_merge(            Array(' info1 ' =$json 1),Array(' Info2 ' =$json 2)          )    ); Echo $newJson;?>

4. File photo Upload upload_file.php

<?Header("content-type:text/html; Charset=utf-8 "); include("configmysql.php"); mysql_select_db("Chepaidb",$q);//database//post Get key-value pair parameters    $TEMPid=$_post[' DriverID ']; Echo"\ndriverid is".$TEMPid." \ n "; foreach($_files  as $_eachfile) {        //file Processing        if($_eachfile["error"] > 0)          {          Echo"Error:".$_eachfile["Error"]. "\ n"; }        Else          {          Echo"File name:".$_eachfile["Name"]. "\ n"; Echo"Type:".$_eachfile["Type"]. "\ n"; Echo"Size:". ($_eachfile["Size"]/1024). "Kb\n"; }         if(file_exists("uploadimage/".$_eachfile["Name"]))            {              Echo $_eachfile["Name"]. "The file already exists."; }        Else            {              Move_uploaded_file($_eachfile["Tmp_name"], "uploadimage/".$_eachfile["Name"]); Echo"The file has been stored in:". " uploadimage/".$_eachfile["Name"]. " \ n "; }    }    /*//file file processing if ($_files["file" ["error"] > 0) {echo "Error:". $_files["File" ["Error"].      "\ n"; } else {echo "file name:". $_files["File" ["Name"].      "\ n"; echo "Type:". $_files["File" ["type"].      "\ n"; echo "Size:". ($_files["File" ["Size"]/1024).       "Kb\n"; } if (File_exists ("uploadimage/". $_files["File" ["Name"])) {echo $_files["file" ["Name"].        "The file already exists."; } else {move_uploaded_file ($_files["file"] ["Tmp_name"], "uploadimage/". $_files["File" ["Nam          E "]); echo "file has been stored in:". " uploadimage/". $_files["File" ["Name"]. "        \ n "; }    */?>

[PHP as the iOS backend JSON format HTTP communication and file upload implementation]

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.