[PHP 作為iOS後台Json格式HTTP通訊及檔案上傳的實現]

來源:互聯網
上載者:User

標籤:

1.資料庫連接 configmysql.php

<?php    $q = mysql_connect("localhost:8889","root","root");    if(!$q)    {       die(‘Could not connect: ‘ . mysql_error());    }    mysql_query("set names utf8"); //以utf8讀取資料    //mysql_select_db("myDB",$q); //選擇資料庫?>

2.POST或GET請求,Json返回 selectuser.php

<?    include("configmysql.php");    mysql_select_db("myDB",$q); //選擇資料庫      //GET或POST取的參數或者    $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;    }    echo json_encode($json);?>

3.多組資料 selectuser.php

<?    include("configmysql.php");    mysql_select_db("chepaiDB",$q); //資料庫      $TEMPid=$_GET[‘Driverid‘];    $sql = "select * from Driverinfo where Driverid=".$TEMPid;    $query = mysql_query($sql)or die(mysql_error());    while($row = mysql_fetch_array($query)){        $json1 = $row;    }        $sql2 = "select * from Driverillegalinfo where IDriverid=".$TEMPid." order by Iid desc";    $query2 = mysql_query($sql2)or die(mysql_error());    $json2 =  array();    $sum=0;    while($row2 = mysql_fetch_array($query2)){        $json2[‘row‘.$sum] = $row2;        $sum++;        }    $newJson = json_encode(          array_merge(            array(‘info1‘ => $json1),            array(‘info2‘ => $json2)          )    );    echo $newJson;?>

4.檔案照片上傳 upload_file.php

<?        header("Content-type: text/html; charset=UTF-8");    include("configmysql.php");    mysql_select_db("chepaiDB",$q); //資料庫      //POST擷取索引值對參數    $TEMPid=$_POST[‘Driverid‘];    echo "\nDriverid is ".$TEMPid."\n";    foreach ($_FILES as $_eachFile) {        //file檔案處理        if ($_eachFile["error"] > 0)          {          echo "錯誤: " . $_eachFile["error"] . "\n";          }        else          {          echo "檔案名稱: " . $_eachFile["name"] . "\n";          echo "類型: " . $_eachFile["type"] . "\n";          echo "大小: " . ($_eachFile["size"] / 1024) . " Kb\n";           }         if (file_exists("uploadimage/" . $_eachFile["name"]))            {              echo $_eachFile["name"] . " 檔案已經存在. ";            }        else            {              move_uploaded_file($_eachFile["tmp_name"],              "uploadimage/" . $_eachFile["name"]);              echo "檔案已經被儲存到: " . "uploadimage/" . $_eachFile["name"]."\n";            }    }    /*    //file檔案處理    if ($_FILES["file"]["error"] > 0)      {      echo "錯誤: " . $_FILES["file"]["error"] . "\n";      }    else      {      echo "檔案名稱: " . $_FILES["file"]["name"] . "\n";      echo "類型: " . $_FILES["file"]["type"] . "\n";      echo "大小: " . ($_FILES["file"]["size"] / 1024) . " Kb\n";       }     if (file_exists("uploadimage/" . $_FILES["file"]["name"]))        {          echo $_FILES["file"]["name"] . " 檔案已經存在. ";        }    else        {          move_uploaded_file($_FILES["file"]["tmp_name"],          "uploadimage/" . $_FILES["file"]["name"]);          echo "檔案已經被儲存到: " . "uploadimage/" . $_FILES["file"]["name"]."\n";        }    */?>

 

[PHP 作為iOS後台Json格式HTTP通訊及檔案上傳的實現]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.