• 关于PHP接收文件的资料


    (一)
    <?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);  
        }  
        ?>

  • 相关阅读:
    (转载)C#控件缩写规范
    ToString()格式和用法大全,C#实现保留两位小数的方法
    C#数字前面如何补0
    (转载)C#语言开发规范
    (转载)C#:Enum、Int和String的互相转换,枚举转换
    [踩坑系列]URLEncode 中对 空格的编码有 “+”和“%20”两种
    [IDEA]IDEA设置注释模板
    [Mybatis]Mybatis 常用标签及功能整理
    [设计模式]静态代理
    记一次java电话面试
  • 原文地址:https://www.cnblogs.com/ck-999/p/5369305.html
Copyright © 2020-2023  润新知