php用 $_Post[‘key’]可以拿到post数据

How to create a basic web service that provides an XML or JSON response using some PHP and MySQL?

How to connect an Android application to a mysql database via PHP web service?

To make this concrete, the goal is a webservice that accepts data in JSON format via a POST request. The data is simply an array of single-digit integers, e.g., [3, 2, 1].

On the server are images named 0.png, 1.png, 2.png, etc. The webservice takes the images corresponding to those specified in the JSON array and composes them into a montage, using the standard ImageMagick command line tool. For example:

montage 3.png 2.png 1.png 321.png

creates a new single image, 321.png, composed of 3.png, 2.png, and 1.png, all in a row.


a simple employee system where the Manager logs in and see all the details of employees who are managed by him:

--Create the database

--Select the database
USE EmployeeDB;

--Create the table
CREATE Table Employees
	Username varchar(20) UNIQUE,
	Password varchar(8),
	Name varchar(40),
	Address varchar(50),
	Manager int references Employees(ID)

Now we’ll insert some values:

Insert into Employees(username,password,name,address)
	values ('guru','123','Guruparan','Colombo');
Insert into Employees (username,password,name,address,manager)
	values ('saman','123','saman','colombo',1);
Insert into Employees (username,password,name,address,manager)
	values ('john','123','john','New York',1);
Insert into Employees(username,password,name,address,manager)
	values ('sean','123','sean','Washington',1);

Now we’ll make the PHP web service which generates the JSON response:

 //Get the name of the Method
 //The method name has to be passed as Method via post
 $Request_Method=$_REQUEST['method'] or die('Method name not found');

 //Connect to the database
 $Connection = mysql_connect("localhost","root","") or die('Cannot connect to Database');

 //Select the database
 mysql_select_db("EmployeeDB") or die('Cannot select Database');

 //Method to verify the users login
 	//username and password are password are passed via querystrings

	//Generate the sql query based on username and password
	$query="select id from Employees where username='$username' and password='$password'";

	//Execute the query
	$result = mysql_query($query);

	//Get the rowcount
	$rowcount= mysql_num_rows($result);

	//if the count is 0 then no matching rows are found
		echo json_encode(array('result'=>0));
	//Else there is an employee with the given credentials
	else {
		$row = mysql_fetch_assoc($result);
		//Get and return his employee id
		echo json_encode(array('result'=>$row['id']));

 //Get all th employees that are managed the by the given emplyee
	$query="select name,address from Employees where manager=$id";
	$result = mysql_query($query);

	while($row = mysql_fetch_assoc($result))
		$resultArray[] = $row;

	echo json_encode($resultArray);
 //Close Connection

Class Employee and the Loginresult: are to be used by JSON to generate the objects
The Constants class: contains the constants such as the URL of the Web service and the user id of the currently logged in user.
server access class: handles the interaction between the server and the Application

imagesURLArray 中存储url,如果你的url是有规律的,都不需要存储,根据规则生成每一个地址然后传参就好了:

$imagesURLArray = array_unique($imagesURLArray );

foreach($imagesURLArray as $imagesURL) {
echo $imagesURL;
echo “<br/>”;
file_put_contents(basename($imagesURL), file_get_contents($imagesURL));

Connect Android and mysql via php webservices[2,4,6]
$nums = json_decode($_REQUEST['nums']);//json_decode.
# Lambda functions are a little less ridiculous in php 5.3 but this is the best
# way I know how to do this in php 5.2:
function f($x) { return "$x.png"; }
$cmd = "montage " . implode(" ", array_map("f", $nums)) . " tmp.png";

/*$cmd = "montage";
foreach($images as $image){
  $cmd .= " ".$image.".png";
$cmd .= " temp.png";*/
exec($cmd); //set a png-header and use readfile or something similar to get you "tmp.png" header('Content-type: image/png'); readfile('tmp.png'); ?>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: