[PHP] Use XAMPP to build a local server, and then use the iOS client to upload data to the local server (three. PHP-side code implementation), Xamppios
I. Installing XAMPP http://www.cnblogs.com/lidongxu/p/5256330.html
Two. Configure MySQL http://www.cnblogs.com/lidongxu/p/5256515.html
And then, today we'll come into contact with the PHP development language
1. First of all, you need to create a new. php file under our Native server folder resource, nonsense (you have to write PHP!)
2. Enter the following code in register.php
Php//1. Obtain the value (this field//is specified here, the front end must abide by this name2, Pass2 etc key value) of the field in the body of the network request that the client uses the Post method$nameP=$_post[' Name2 '];$passP=$_post[' Pass2 '];$ageP=$_post[' Age2 '];$telephoneP=$_post[' Telephone2 '];//2. Establish a database connection (the IP address where the 127.0.0.1 database resides)//root is the database user name (default)//"" Password (default is empty)$con=mysql_connect("127.0.0.1", "Root", "" ");$myCon=mysql_select_db("Lidongxu",$con);//3. Check first, if present, do not insert the$select= "Select UserName from User where userName = '$nameP'";$seleResult=mysql_query($select);//4. If it is found that the user is already present, then return-1 to the client representative has already registeredif(mysql_num_rows($seleResult)) {//success is the value of the key that corresponds to the string that follows $a=Array(); $a[' success '] = "1"; $a[' status '] = "have"; $arr= Json_encode ($a); Echo $arr;}//5. If you have not registered, thenElse {//6. Insert the data into the MySQL database $sql= "INSERT into User values ('$nameP', '$passP', '$ageP', '$telephoneP')"; $result=mysql_query($sql); if($result= = 1) {//7. Successful execution of the representative $a=Array(); $a[' success '] = "1"; $a[' status '] = "OK"; $arr= Json_encode ($a); Echo $arr; } Else{//8. Failed to insert on behalf of $a=Array(); $a[' success '] = "0"; $a[' status '] = "no"; $arr= Json_encode ($a); Echo $arr; }}//9. Receive picture of user picture//9.1. Receive images to the default temporary file path on the server and the name (UploadFile to//field used by the foreground)$url=$_files["Uploadimagefile"] ["Tmp_name"];//9.2 Get the path under the Downloads folder under the root path (DOWNLOAD2 requires manual//go-local creation)$destination _folder=$_server[' Document_root ']. ' /download2/'; //9.3 Stitching to be saved as a file name on the server $newfname=$destination _folder. (string)$nameP.'. JPG ';//Set your file ext//open a connection rb+ read and write open a binary file that allows read and write data, and the file must exist. Get the files that are uploaded to the cache folder by the client $file=fopen($url, "RB"); if($file) { //a write-only file opens in an additional way. If the file does not exist, the file will be created, and if the file exists, the data written will be added to the end of the file, that is, the original content of the file will be retained. Get the name of the file you want to pass the client over to the new folder $NEWF=fopen($newfname, "a"); if($NEWF) //checks whether the file ends, such as ending, returns a value other than 0 while(!feof($file)) { //start reading 1MB from a file and write to the new path 1MB fwrite($NEWF,fread($file, 1024 * 8), 1024 * 8 ); } } if($file) { //Close File Link fclose($file); } if($NEWF) { fclose($NEWF); } ?>
3. Then create a new Download2 folder under the local server folder
4. Then write the login PHP code too! Under the Htdocs folder, create a new loginget.php file and insert the code
Php//1. Get the key value corresponding to the value//declaration variable name1 and PASS1 receive in the Get Network request URL$name 1=$_get[' Name '];$pass 1=$_get[' Pass '];//2. Establish database connection//parameter 1: The address of the server where the database resides (native 127.0.0.1 or localhost)//parameter 2:mysql the account of the database (default root)//parameter 3:mysql the password of the database (default none)$con=mysql_connect("127.0.0.1", "Root", "" ");//parameter 1: Name of the database you created$myCon=mysql_select_db("Lidongxu",$con);//3. Execute the query (using the username and password to match the lookup, if found the random return username (user name))$sql= "SELECT * from User where userName = '$name 1' and password = '$pass 1'";//4. Receive Results$result=mysql_query($sql);//4.2 If the query results are emptyif(mysql_num_rows($result) = = 0) { $a=Array(); $a[' success '] = "0"; $a[' name '] = "NULL"; $a[' status '] = "no"; $arr= Json_encode ($a); Echo $arr; }Else {//5. Remove this record$row=Mysql_fetch_row($result); $a=Array(); $a[' success '] = "1"; $a[' name '] =$row[0]; $a[' age '] =$row[2]; $a[' telephone '] =$row[3]; $a[' status '] = "OK"; $arr= Json_encode ($a); Echo $arr; } ?>
Here, PHP temporarily reported a section of the way, and then the development of iOS code (happy not???)
To write iOS code ...... http://www.cnblogs.com/lidongxu/p/5267753.html
http://www.bkjia.com/PHPjc/1108337.html www.bkjia.com true http://www.bkjia.com/PHPjc/1108337.html techarticle [PHP] use XAMPP to build a local server, and then use the iOS client to upload data to the local server (three. PHP-side code implementation), Xamppios. Install Xampp Http://www.cnblogs.com/lidongxu ...