Information about receiving files from PHP

Source: Internet
Author: User

A
<?php
$base _path = "./upload/"; Receive file directory
$target _path = $base _path. basename ($_files [' UploadFile '] [' name ']);
if (Move_uploaded_file ($_files [' UploadFile '] [' tmp_name '], $target _path)) {
$array = Array (
"Code" = "1",
"Message" = $_files [' UploadFile '] [' name ']
);
echo Json_encode ($array);
} else {
$array = Array (
"Code" = "0",
"Message" = "There is an error uploading the file, please try again!". $_files [' UploadFile '] [' ERROR ']
);
echo Json_encode ($array);
}
?>
Two
<?php
Array for JSON response

Here, you need to change the database name and the indicated password to your own
$con = mysql_connect ("localhost", "root", null);
if (! $con) {
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("a0722152915", $con);




$response = Array ();
Include ("conn.php");
Check for required fields
if (Isset ($_post[' time ') && isset ($_post[' lat ')) && isset ($_post[' lon ']) && isset ($_post[') Encyptiontype ']) && isset ($_post[' Rssi ') && isset ($_post[' name ']) {
$time = $_post[' time '];
$lat = $_post[' lat '];
$lon = $_post[' lon ');
$encyptiontype = $_post[' Encyptiontype ');
$rssi = $_post[' Rssi '];
$name = $_post[' name '];
$result = mysql_query ("INSERT into Wifi_state (time, lat, lon,encyptiontype,rssi,name) VALUES (' $time ', ' $lat ', ' $lon ', ' $ Encyptiontype ', ' $rssi ', ' $name ');
echo $result;
Check if row inserted or not
if ($result) {
Successfully inserted into database
$response ["Success"] = 1;
$response ["message"] = "Product successfully created.";
Echoing JSON response
echo Json_encode ($response);
} else {
Failed to insert row
$response ["success"] = 0;
$response ["message"] = "oops! An error occurred. ";
Echoing JSON response
echo Json_encode ($response);
}
} else {
Required field is missing
$response ["success"] = 0;
$response ["message"] = "Required field (s) is missing";
Echoing JSON response
echo Json_encode ($response);
}
?>

Information about receiving files from PHP

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.