• 关于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);  
        }  
        ?>

  • 相关阅读:
    spring boot项目配置文件集合
    分享一个dapper简单封装
    Pgsql数据库jsonb操作函数集合
    RocketMq消息队列使用
    PostgreSQL相关的软件,库,工具和资源集合
    java消息队列使用场景
    java转c#代码工具集合
    Spring基于注解的Cache支持
    MKDOCS在线文档编辑器
    Plinq-Parallel.ForEach for 性能提升
  • 原文地址:https://www.cnblogs.com/ck-999/p/5369305.html
Copyright © 2020-2023  润新知