码迷,mamicode.com
首页 > Web开发 > 详细

关于PHP接收文件的资料

时间:2016-04-08 19:53:42      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

(一)
<?php
$base_path = "./upload/"; // 接收文件目录
$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 was an error uploading the file, please try again!" . $_FILES [‘uploadfile‘] [‘error‘]
    );
    echo json_encode ( $array );
}
?>
(二)
    <?php  
    // array for JSON response  
     
    //此处需要将数据库名和表明还有密码做相应修改,改成你自己的 
    $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);  
    }  
    ?>

关于PHP接收文件的资料

标签:

原文地址:http://www.cnblogs.com/ck-999/p/5369305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!